*-------------------------------------------------------------------------------

global main		"~\Dropbox\Laptop\A_projects\BMG\Data"
global figures	"$main/figures"
global tables	 "$main/tables"

set varabbrev off, permanently
*-------------------------------------------------------------------------------



/*

RQ2: To what extent does peer behavior influence individual SSP decisions to purchase inputs or sell outputs? 

*/

********************************************************************************
*								INPUT MARKET								   *
********************************************************************************


*-------------------------------	SEEDS	------------------------------------

/*

			   GHANA

	(Repeated Cross-sections)
*/

use "$main/GhaData.dta",clear
drop if t==2
keep if SSP
keep if !missing(production)
keep if production>0

lab var seedherd "Share of peers buying"

gl x 	agehead i.female litrate hhsize nasset livestock						///
		i.cereals i.rootubs i.grainlg i.oilseed i.frutveg i.trecrop i.indcrop	///
		i.fertilizer i.pesticides i.hirlmarket i.agrocredit i.rural i.t

gl w 	c.dealerdens##c.dealerdens i.govinpdensd farmsize ///
		ihs_rwagecashpc ihs_rofsecashpc ihs_rnonlcashpc roadensity distmarket i.favzone

qui svy: probit seedmarket c.seedherd##c.seedherd $w $x 
predict y
sum y,meanonly
local cmean = r(mean)

lab var seedherd "Share of peers buying"
qui margins if e(sample), dydx(seedherd) vce(unconditional) post
nlcom	(seedherd:		_b[seedherd]), post	
est store gha_1
			
outreg2 using "$tables/Table9.doc", dec(3) adec(3) label ctitle(GHA:12-17) ///
	title("Peer effect on own seed market participation") ///
	addstat("Seed market participation", 	`cmean') ///
	addtext(Year FE, YES, Location FE, YES, Other controls, YES) alpha(0.01, 0.05) ///
	symbol(***, **) nodepvar replace	
	
*----------------------------------	2017 Only ----------------------------------

keep if t==5

gl x 	agehead i.female litrate hhsize nasset livestock						///
		i.cereals i.rootubs i.grainlg i.oilseed i.frutveg i.trecrop i.indcrop	///
		i.fertilizer i.pesticides i.hirlmarket i.agrocredit i.rural

gl w 	dealerdens i.govinpdensd farmsize ///
		ihs_rwagecashpc ihs_rofsecashpc ihs_rnonlcashpc roadensity distmarket i.favzone

qui svy: probit seedmarket c.seedherd##c.seedherd $w $x 
drop y
predict y
sum y,meanonly
local cmean = r(mean)

lab var seedherd "Share of peers buying"
qui margins if e(sample), dydx(seedherd) vce(unconditional) post
nlcom	(seedherd:		_b[seedherd]), post
est store gha_2
			
outreg2 using "$tables/Table9A.doc", dec(3) adec(3) label ctitle(GHA:2017) ///
	title("Peer effect on own seed market participation") ///
	addstat("Seed market participation", 	`cmean') ///
	addtext(Year FE, NO, Location FE, YES, Other controls, YES) alpha(0.01, 0.05) ///
	symbol(***, **) nodepvar replace
	
*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

	
/*

			NIGERIA

		  (2011-2016)
*/

use "$main/NigPanel.dta",clear

keep if SSP
keep if short==1
keep if !missing(production)
keep if production>0
bysort id (t): drop if _N == 1

gl a 	seedherd dealerdens govinpdensd farmsize ihs_rwagecashpc ihs_rofsecashpc ihs_rnonlcashpc ///
		litrate hhsize nasset livestock	cereals rootubs grainlg ///
		oilseed frutveg trecrop indcrop roadensity distmarket	///
		fertilizer pesticides hirlmarket agrocredit
		
foreach v in $a {

egen m_`v' = mean(`v'),by(id)

}

svyset cl [pweight = cpw], strata(strata) vce(linearized) singleunit(scaled)

gl x 	agehead i.female litrate hhsize nasset livestock						///
		i.cereals i.rootubs i.grainlg i.oilseed i.frutveg i.trecrop i.indcrop	///
		i.fertilizer i.pesticides i.hirlmarket i.agrocredit i.rural i.t
*
gl m 	m_seedherd c.m_dealerdens##c.m_dealerdens m_govinpdensd m_farmsize ///
		m_ihs_rwagecashpc m_ihs_rofsecashpc m_ihs_rnonlcashpc 					///
		m_litrate m_hhsize m_nasset m_livestock	m_cereals m_rootubs m_grainlg 	///
		m_oilseed m_frutveg m_trecrop m_indcrop c.m_roadensity##c.m_roadensity m_distmarket		///
		m_fertilizer m_pesticides m_hirlmarket m_agrocredit

gl w 	c.dealerdens##c.dealerdens i.govinpdensd farmsize 		///
		ihs_rwagecashpc ihs_rofsecashpc ihs_rnonlcashpc c.roadensity##c.roadensity distmarket i.favzone

qui svy: probit seedmarket seedherd $w $x $m
predict y
sum y,meanonly
local cmean = r(mean)

lab var seedherd "Share of peers buying"
qui margins if e(sample), dydx(seedherd) vce(unconditional) post
nlcom	(seedherd:		_b[seedherd]), post
est store nig_1
		
outreg2 using "$tables/Table9.doc", dec(3) adec(3) label ctitle(NIG:11-16) ///
	addstat("Seed market participation", 		`cmean') ///
	addtext(Year FE, YES, Location FE, YES, Other controls, YES) alpha(0.01, 0.05) ///
	symbol(***, **) nodepvar	
	
	
*----------------------------------	2019 Only ----------------------------------

use "$main/NigPanel.dta",clear
keep if t==4
keep if SSP
keep if !missing(production)
keep if production>0

svyset clust [pweight = weight], strata(strata) vce(linearized) singleunit(scaled)

gl x 	agehead i.female litrate hhsize nasset livestock						///
		i.cereals i.rootubs i.grainlg i.oilseed i.frutveg i.trecrop i.indcrop	///
		i.fertilizer i.pesticides i.hirlmarket i.agrocredit i.rural

gl w 	dealerdens i.govinpdensd farmsize 		///
		ihs_rwagecashpc ihs_rofsecashpc ihs_rnonlcashpc roadensity distmarket i.favzone

qui svy: probit seedmarket seedherd $w $x
predict y
sum y,meanonly
local cmean = r(mean)

lab var seedherd "Share of peers buying"
qui margins if e(sample), dydx(seedherd) vce(unconditional) post
nlcom	(seedherd:		_b[seedherd]), post
est store nig_2
		
outreg2 using "$tables/Table9A.doc", dec(3) adec(3) label ctitle(NIG:2019) ///
	addstat("Seed market participation", 		`cmean') ///
	addtext(Year FE, NO, Location FE, YES, Other controls, YES) alpha(0.01, 0.05) ///
	symbol(***, **) nodepvar	

*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

/*

			TANZANIA

		   (2015 & 2020)
*/

use "$main/TanPanel.dta",clear
keep if SSP
keep if short==1
keep if !missing(production)
keep if production>0
bysort id (t): drop if _N == 1
  
gl a 	seedherd dealerdens govinpdensd farmsize ihs_rwagecashpc ihs_rofsecashpc ihs_rnonlcashpc ///
		litrate hhsize nasset livestock	cereals rootubs grainlg ///
		oilseed frutveg trecrop indcrop roadensity distmarket	///
		fertilizer pesticides hirlmarket agrocredit
		
foreach v in $a {

egen m_`v' = mean(`v'),by(id)

}

svyset cl [pweight = cpw], strata(strata) vce(linearized) singleunit(scaled)

gl x 	agehead i.female litrate hhsize nasset livestock						///
		i.cereals i.rootubs i.grainlg i.oilseed i.frutveg i.trecrop i.indcrop	///
		i.fertilizer i.pesticides i.hirlmarket i.agrocredit i.rural i.t 
*
gl m 	m_seedherd m_dealerdens m_govinpdensd m_farmsize ///
		m_ihs_rwagecashpc m_ihs_rofsecashpc m_ihs_rnonlcashpc 					///
		m_litrate m_hhsize m_nasset m_livestock	m_cereals m_rootubs m_grainlg 	///
		m_oilseed m_frutveg m_trecrop m_indcrop m_roadensity m_distmarket		///
		m_fertilizer m_pesticides m_hirlmarket m_agrocredit

gl w 	dealerdens i.govinpdensd farmsize 		///
		ihs_rwagecashpc ihs_rofsecashpc ihs_rnonlcashpc roadensity distmarket i.favzone

qui svy: probit seedmarket seedherd $w $x $m
predict y
sum y,meanonly
local cmean = r(mean)

lab var seedherd "Share of peers buying"
qui margins if e(sample), dydx(seedherd) vce(unconditional) post
nlcom	(seedherd:		_b[seedherd]), post
est store tan_1
		
outreg2 using "$tables/Table9.doc", dec(3) adec(3) label ctitle(TAN:15-20) ///
	addstat("Seed market participation", 		`cmean') ///
	addtext(Year FE, YES, Location FE, YES, Other controls, YES) alpha(0.01, 0.05) ///
	symbol(***, **) nodepvar	
	
*-------------------------------- 2009, 2011 & 2013 ----------------------------

use "$main/TanPanel.dta",clear
keep if SSP
keep if longp==1
keep if !missing(production)
keep if production>0
bysort id (t): drop if _N == 1

gl a 	seedherd dealerdens govinpdensd farmsize ihs_rwagecashpc ihs_rofsecashpc ihs_rnonlcashpc ///
		litrate hhsize nasset livestock	cereals rootubs grainlg ///
		oilseed frutveg trecrop indcrop roadensity distmarket	///
		fertilizer pesticides hirlmarket agrocredit
		
foreach v in $a {

egen m_`v' = mean(`v'),by(id)

}

svyset cl [pweight = cpw], strata(strata) vce(linearized) singleunit(scaled)

gl x 	agehead i.female litrate hhsize nasset livestock						///
		i.cereals i.rootubs i.grainlg i.oilseed i.frutveg i.trecrop i.indcrop	///
		i.fertilizer i.pesticides i.hirlmarket i.agrocredit i.rural i.t
*
gl m 	c.m_seedherd##c.m_seedherd m_dealerdens m_govinpdensd m_farmsize ///
		m_ihs_rwagecashpc m_ihs_rofsecashpc m_ihs_rnonlcashpc 					///
		m_litrate m_hhsize m_nasset m_livestock	m_cereals m_rootubs m_grainlg 	///
		m_oilseed m_frutveg m_trecrop m_indcrop m_roadensity m_distmarket		///
		m_fertilizer m_pesticides m_hirlmarket m_agrocredit

gl w 	dealerdens i.govinpdensd farmsize 		///
		ihs_rwagecashpc ihs_rofsecashpc ihs_rnonlcashpc roadensity distmarket i.favzone
*
qui svy: probit seedmarket c.seedherd##c.seedherd $w $x $m
predict y
sum y,meanonly
local cmean = r(mean)

lab var seedherd "Share of peers buying"
qui margins if e(sample), dydx(seedherd) vce(unconditional) post
nlcom	(seedherd:		_b[seedherd]), post
est store tan_2
		
outreg2 using "$tables/Table9A.doc", dec(3) adec(3) label ctitle(TAN:09-13) ///
	addstat("Seed market participation", 		`cmean') ///
	addtext(Year FE, YES, Location FE, YES, Other controls, YES) alpha(0.01, 0.05) ///
	symbol(***, **) nodepvar	
*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

	
/*

			UGANDA

		  (2016 & 2020)
*/

use "$main/UgaPanel.dta",clear
keep if SSP
keep if short==1
keep if !missing(production)
keep if production>0
bysort id (t): drop if _N == 1
  
gl a 	seedherd dealerdens govinpdensd farmsize ihs_rwagecashpc ihs_rofsecashpc ihs_rnonlcashpc ///
		litrate hhsize nasset livestock	cereals rootubs grainlg ///
		oilseed frutveg trecrop indcrop roadensity distmarket	///
		fertilizer pesticides hirlmarket agrocredit
		
foreach v in $a {

egen m_`v' = mean(`v'),by(id)

}

svyset cl [pweight = cpw], strata(strata) vce(linearized) singleunit(scaled)

gl x 	agehead i.female litrate hhsize nasset livestock						///
		i.cereals i.rootubs i.grainlg i.oilseed i.frutveg i.trecrop i.indcrop	///
		i.fertilizer i.pesticides i.hirlmarket i.agrocredit i.rural i.t
	
gl m 	c.m_seedherd##c.m_seedherd m_dealerdens m_govinpdensd m_farmsize ///
		m_ihs_rwagecashpc m_ihs_rofsecashpc m_ihs_rnonlcashpc 					///
		m_litrate m_hhsize m_nasset m_livestock	m_cereals m_rootubs m_grainlg 	///
		m_oilseed m_frutveg m_trecrop m_indcrop m_roadensity m_distmarket		///
		m_fertilizer m_pesticides m_hirlmarket m_agrocredit

gl w 	dealerdens i.govinpdensd farmsize 		///
		ihs_rwagecashpc ihs_rofsecashpc ihs_rnonlcashpc roadensity distmarket i.favzone

qui svy: probit seedmarket c.seedherd##c.seedherd $w $x $m
predict y
sum y,meanonly
local cmean = r(mean)

lab var seedherd "Share of peers buying"
qui margins if e(sample), dydx(seedherd) vce(unconditional) post
nlcom	(seedherd:		_b[seedherd]), post	
est store uga_1
		
outreg2 using "$tables/Table9.doc", dec(3) adec(3) label ctitle(UGA:16-20) ///
	addstat("Seed market participation", 		`cmean') ///
	addtext(Year FE, YES, Location FE, YES, Other controls, YES) alpha(0.01, 0.05) ///
	symbol(***, **) nodepvar	
	
*-------------------------------- 2010, 2012, 2014) ----------------------------

use "$main/UgaPanel.dta",clear
keep if SSP
keep if medip==1
keep if !missing(production)
keep if production>0
bysort id (t): drop if _N == 1
  
gl a 	seedherd dealerdens govinpdensd farmsize ihs_rwagecashpc ihs_rofsecashpc ihs_rnonlcashpc ///
		litrate hhsize nasset livestock	cereals rootubs grainlg ///
		oilseed frutveg trecrop indcrop roadensity distmarket	///
		fertilizer pesticides hirlmarket agrocredit
		
foreach v in $a {

egen m_`v' = mean(`v'),by(id)

}

svyset cl [pweight = cpw], strata(strata) vce(linearized) singleunit(scaled)

gl x 	agehead i.female litrate hhsize nasset livestock						///
		i.cereals i.rootubs i.grainlg i.oilseed i.frutveg i.trecrop i.indcrop	///
		i.fertilizer i.pesticides i.hirlmarket i.agrocredit i.t i.rural i.t
		
gl m 	m_seedherd c.m_dealerdens##c.m_dealerdens m_govinpdensd m_farmsize ///
		m_ihs_rwagecashpc m_ihs_rofsecashpc m_ihs_rnonlcashpc 					///
		m_litrate m_hhsize m_nasset m_livestock	m_cereals m_rootubs m_grainlg 	///
		m_oilseed m_frutveg m_trecrop m_indcrop m_roadensity m_distmarket		///
		m_fertilizer m_pesticides m_hirlmarket m_agrocredit

gl w 	c.dealerdens##c.dealerdens i.govinpdensd farmsize 		///
		ihs_rwagecashpc ihs_rofsecashpc ihs_rnonlcashpc roadensity distmarket i.favzone
		
qui svy: probit seedmarket seedherd $w $x $m
predict y
sum y,meanonly
local cmean = r(mean)

lab var seedherd "Share of peers buying"
qui margins if e(sample), dydx(seedherd) vce(unconditional) post
nlcom	(seedherd:		_b[seedherd]), post	
est store uga_2	
		
outreg2 using "$tables/Table9A.doc", dec(3) adec(3) label ctitle(UGA:10-14) ///
	addstat("Seed market participation", 		`cmean') ///
	addtext(Year FE, YES, Location FE, YES, Other controls, YES) alpha(0.01, 0.05) ///
	symbol(***, **) nodepvar	
*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

	
/*

			ETHIOPIA

		(2012, 2014 & 2016)
*/

use "$main/EthPanel.dta",clear
keep if SSP
keep if longp==1
keep if !missing(production)
keep if production>0
bysort id (t): drop if _N == 1

gl a 	seedherd dealerdens govinpdensd farmsize ihs_rwagecashpc ihs_rofsecashpc ihs_rnonlcashpc ///
		litrate hhsize nasset livestock	cereals rootubs grainlg ///
		oilseed frutveg trecrop indcrop roadensity distmarket	///
		fertilizer pesticides hirlmarket agrocredit
		
foreach v in $a {

egen m_`v' = mean(`v'),by(id)

}

svyset cl [pweight = cpw], strata(strata) vce(linearized) singleunit(scaled)

gl x 	agehead i.female litrate hhsize nasset livestock						///
		i.cereals i.rootubs i.grainlg i.oilseed i.frutveg i.trecrop i.indcrop	///
		i.fertilizer i.pesticides i.hirlmarket i.agrocredit i.t i.rural
	
gl m 	m_seedherd m_dealerdens m_govinpdensd m_farmsize ///
		m_ihs_rwagecashpc m_ihs_rofsecashpc m_ihs_rnonlcashpc 					///
		m_litrate m_hhsize m_nasset m_livestock	m_cereals m_rootubs m_grainlg 	///
		m_oilseed m_frutveg m_trecrop m_indcrop m_roadensity m_distmarket		///
		m_fertilizer m_pesticides m_hirlmarket m_agrocredit

gl w 	dealerdens i.govinpdensd farmsize 		///
		ihs_rwagecashpc ihs_rofsecashpc ihs_rnonlcashpc roadensity distmarket i.favzone

qui svy: probit seedmarket seedherd $w $x $m
predict y
sum y,meanonly
local cmean = r(mean)

lab var seedherd "Share of peers buying"
qui margins if e(sample), dydx(seedherd) vce(unconditional) post
nlcom	(seedherd:		_b[seedherd]), post	
est store eth_1
		
outreg2 using "$tables/Table9.doc", dec(3) adec(3) label ctitle(ETH:12-16) ///
	addstat("Seed market participation", 		`cmean') ///
	addtext(Year FE, YES, Location FE, YES, Other controls, YES) alpha(0.01, 0.05) ///
	symbol(***, **) nodepvar		
	
*-------------------------------- 	2019 Only		----------------------------
	
use "$main/EthPanel.dta",clear
keep if t==4
keep if SSP
keep if !missing(production)
keep if production>0
	
gl x 	agehead i.female litrate hhsize nasset livestock						///
		i.cereals i.rootubs i.grainlg i.oilseed i.frutveg i.trecrop i.indcrop	///
		i.fertilizer i.pesticides i.hirlmarket i.agrocredit i.rural

gl w 	dealerdens i.govinpdensd farmsize 		///
		ihs_rwagecashpc ihs_rofsecashpc ihs_rnonlcashpc c.roadensity##c.roadensity distmarket i.favzone

qui svy: probit seedmarket seedherd $w $x
predict y
sum y,meanonly
local cmean = r(mean)

lab var seedherd "Share of peers buying"
qui margins if e(sample), dydx(seedherd) vce(unconditional) post
nlcom	(seedherd:		_b[seedherd]), post	
est store eth_2
		
outreg2 using "$tables/Table9A.doc", dec(3) adec(3) label ctitle(ETH:2019) ///
	addstat("Seed market participation", 		`cmean') ///
	addtext(Year FE, NO, Location FE, YES, Other controls, YES) alpha(0.01, 0.05) ///
	symbol(***, **) nodepvar		

*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

	
/*

			MALAWI

	(2011, 2013, 2016 & 2019)
*/

use "$main/MalPanel.dta",clear
keep if SSP
keep if !missing(production)
keep if production>0
bysort id (t): drop if _N == 1
  
gl a 	seedherd dealerdens govinpdensd farmsize ihs_rwagecashpc ihs_rofsecashpc ihs_rnonlcashpc ///
		litrate hhsize nasset livestock	cereals rootubs grainlg ///
		oilseed frutveg trecrop indcrop roadensity distmarket	///
		fertilizer pesticides hirlmarket agrocredit
		
foreach v in $a {

egen m_`v' = mean(`v'),by(id)

}

svyset cl [pweight = cpw], strata(strata) vce(linearized) singleunit(scaled)

gl x 	agehead i.female litrate hhsize nasset livestock						///
		i.cereals i.rootubs i.grainlg i.oilseed i.frutveg i.trecrop i.indcrop	///
		i.fertilizer i.pesticides i.hirlmarket i.agrocredit i.rural i.t 

gl m 	m_seedherd m_dealerdens m_govinpdensd m_farmsize ///
		m_ihs_rwagecashpc m_ihs_rofsecashpc m_ihs_rnonlcashpc 					///
		m_litrate m_hhsize m_nasset m_livestock	m_cereals m_rootubs m_grainlg 	///
		m_oilseed m_frutveg m_trecrop m_indcrop m_roadensity m_distmarket		///
		m_fertilizer m_pesticides m_hirlmarket m_agrocredit

gl w 	dealerdens i.govinpdensd farmsize 		///
		ihs_rwagecashpc ihs_rofsecashpc ihs_rnonlcashpc roadensity distmarket i.favzone

qui svy: probit seedmarket seedherd $w $x $m
predict y
sum y,meanonly
local cmean = r(mean)

lab var seedherd "Share of peers buying"
qui margins if e(sample), dydx(seedherd) vce(unconditional) post
nlcom	(seedherd:		_b[seedherd]), post	
est store mal_1
		
outreg2 using "$tables/Table9.doc", dec(3) adec(3) label ctitle(MAL:11-19) ///
	addstat("Seed market participation", 		`cmean') ///
	addtext(Year FE, YES, Location FE, YES, Other controls, YES) alpha(0.01, 0.05) ///
	symbol(***, **) nodepvar	


*-------------------------------- 	2016 & 2019		----------------------------

use "$main/MalPanel.dta",clear
keep if SSP
keep if short==1
keep if !missing(production)
keep if production>0
bysort id (t): drop if _N == 1
  
gl a 	seedherd dealerdens govinpdensd farmsize ihs_rwagecashpc ihs_rofsecashpc ihs_rnonlcashpc ///
		litrate hhsize nasset livestock	cereals rootubs grainlg ///
		oilseed frutveg trecrop indcrop roadensity distmarket	///
		fertilizer pesticides hirlmarket agrocredit
		
foreach v in $a {

egen m_`v' = mean(`v'),by(id)

}

svyset cl [pweight = cpw], strata(strata) vce(linearized) singleunit(scaled)

gl x 	agehead i.female litrate hhsize nasset livestock						///
		i.cereals i.rootubs i.grainlg i.oilseed i.frutveg i.trecrop i.indcrop	///
		i.fertilizer i.pesticides i.hirlmarket i.agrocredit i.rural i.t 

gl m 	m_seedherd m_dealerdens m_govinpdensd m_farmsize ///
		m_ihs_rwagecashpc m_ihs_rofsecashpc m_ihs_rnonlcashpc 					///
		m_litrate m_hhsize m_nasset m_livestock	m_cereals m_rootubs m_grainlg 	///
		m_oilseed m_frutveg m_trecrop m_indcrop m_roadensity m_distmarket		///
		m_fertilizer m_pesticides m_hirlmarket m_agrocredit

gl w 	dealerdens i.govinpdensd farmsize 		///
		ihs_rwagecashpc ihs_rofsecashpc ihs_rnonlcashpc roadensity distmarket i.favzone

qui svy: probit seedmarket seedherd $w $x $m
predict y
sum y,meanonly
local cmean = r(mean)

lab var seedherd "Share of peers buying"
qui margins if e(sample), dydx(seedherd) vce(unconditional) post
nlcom	(seedherd:		_b[seedherd]), post	
est store mal_2
		
outreg2 using "$tables/Table9A.doc", dec(3) adec(3) label ctitle(MAL:16-19) ///
	addstat("Seed market participation", 		`cmean') ///
	addtext(Year FE, YES, Location FE, YES, Other controls, YES) alpha(0.01, 0.05) ///
	symbol(***, **) nodepvar	


********************************************************************************

coefplot(gha_1,		ms(D)  mc(black) ciopts(recast(rcap) lc(black) lp(longdash)))	///
		(nig_1,		ms(D)  mc(black) ciopts(recast(rcap) lc(black) lp(longdash)))	///
		(tan_1,		ms(D)  mc(black) ciopts(recast(rcap) lc(black) lp(longdash)))	///
		(uga_1,		ms(D)  mc(black) ciopts(recast(rcap) lc(black) lp(longdash)))	///
		(eth_1,		ms(D)  mc(black) ciopts(recast(rcap) lc(black) lp(longdash)))	///
		(mal_1,		ms(D)  mc(black) ciopts(recast(rcap) lc(black) lp(longdash))),	///
		asequation swapnames xline(0, lp(solid) lc(red)) levels(95) legend(off) 	///
     eqren(gha_1 = "GHA (06-17)" 		///
           nig_1 = "NIG (11-16)"		///
		   tan_1 = "TAN (15-20)" 		///
           uga_1 = "UGA (16-20)"		///
           eth_1 = "ETH (12-16)"		///
           mal_1 = "MAL (11-19)")		///
   		   ylab(, nogrid) xlab(, nogrid) ///
		mlabel format(%9.2f) mlabpos(12) mlabcol(black) mlabgap(*2) grid(none)		///
		legend(off) xtitle("Marginal effect") xlab(-.50(.50)1, format(%9.1f) nogrid)  ///
		title("{bf: (A)}" "{bf:Main regressions with most}" "{bf: recent panels/repeated cross-section}", size(medsmall)) name(graph1, replace) 
	
*-------------------------------------------------------------------------------

coefplot(gha_2,		ms(D)  mc(black) ciopts(recast(rcap) lc(black) lp(longdash)))	///
		(nig_2,		ms(D)  mc(black) ciopts(recast(rcap) lc(black) lp(longdash)))	///
		(tan_2,		ms(D)  mc(black) ciopts(recast(rcap) lc(black) lp(longdash)))	///
		(uga_2,		ms(D)  mc(black) ciopts(recast(rcap) lc(black) lp(longdash)))	///
		(eth_2,		ms(D)  mc(black) ciopts(recast(rcap) lc(black) lp(longdash)))	///
		(mal_2,		ms(D)  mc(black) ciopts(recast(rcap) lc(black) lp(longdash))),	///
		asequation swapnames xline(0, lp(solid) lc(red)) levels(95) legend(off) 	///
     eqren(gha_2 = "GHA (2017)" 		///
           nig_2 = "NIG (2019)"			///
		   tan_2 = "TAN (09-13)" 		///
           uga_2 = "UGA (10-14)"		///
           eth_2 = "ETH (2019)"			///
           mal_2 = "MAL (16-19)")		///
   		   ylab(, nogrid) xlab(, nogrid) ///
		mlabel format(%9.2f) mlabpos(12) mlabcol(black) mlabgap(*2) grid(none)		///
		legend(off) xtitle("Marginal effect") xlab(-.50(.50)1, format(%9.1f) nogrid)  ///
		title("{bf: (B)}" "{bf:Supplementary regressions with}" "{bf: other panels/recent cross-sections}", size(medsmall)) name(graph2, replace) 

graph combine graph1 graph2, imargin(tiny) col(2) iscale(1) 
graph export "$figures/SeedsPeer.tif", as(tif) name("Graph") replace

*------------------------------- FERTILIZER	------------------------------------

/*

			   GHANA

	(Repeated Cross-sections)
*/

use "$main/GhaData.dta",clear
drop if t==2
keep if SSP
keep if !missing(production)
keep if production>0

gl x 	agehead i.female litrate hhsize nasset livestock						///
		i.cereals i.rootubs i.grainlg i.oilseed i.frutveg i.trecrop i.indcrop	///
		i.seedmarket i.pesticides i.hirlmarket i.agrocredit i.rural i.t
*
gl w 	dealerdens i.govinpdensd c.farmsize##c.farmsize ///
		ihs_rwagecashpc ihs_rofsecashpc ihs_rnonlcashpc roadensity distmarket i.favzone

qui svy: probit fertilizer c.fertherd##c.fertherd $x $w
predict y
sum y,meanonly
local cmean = r(mean)

lab var fertherd "Share of peers buying"
qui margins if e(sample), dydx(fertherd) vce(unconditional) post
nlcom	(fertherd:		_b[fertherd]), post	
est store gha_1
			
outreg2 using "$tables/Table10.doc", dec(3) adec(3) label ctitle(GHA:12-17) ///
	title("Peer effect on own fertilizer market participation") ///
	addstat("Fertilizer market participation", 		`cmean') ///
	addtext(Year FE, YES, Location FE, YES, Other controls, YES) alpha(0.01, 0.05) ///
	symbol(***, **) nodepvar replace	
	
*----------------------------------	2017 Only ----------------------------------

keep if t==5

gl x 	agehead i.female litrate hhsize nasset livestock						///
		i.cereals i.rootubs i.grainlg i.oilseed i.frutveg i.trecrop i.indcrop	///
		i.seedmarket i.pesticides i.hirlmarket i.agrocredit i.rural
		
gl w 	dealerdens i.govinpdensd c.farmsize##c.farmsize ///
		ihs_rwagecashpc ihs_rofsecashpc ihs_rnonlcashpc roadensity distmarket i.favzone

qui svy: probit fertilizer fertherd $x $w
drop y
predict y
sum y,meanonly
local cmean = r(mean)

lab var fertherd "Share of peers buying"
qui margins if e(sample), dydx(fertherd) vce(unconditional) post
nlcom	(fertherd:		_b[fertherd]), post	
est store gha_2
			
outreg2 using "$tables/Table10A.doc", dec(3) adec(3) label ctitle(GHA:2017) ///
	title("Peer effect on own fertilizer market participation") ///
	addstat("Fertilizer market participation", 		`cmean') ///
	addtext(Year FE, YES, Location FE, YES, Other controls, YES) alpha(0.01, 0.05) ///
	symbol(***, **) nodepvar replace	

*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

	
/*

			NIGERIA

		  (2011-2016)
*/

use "$main/NigPanel.dta",clear

keep if SSP
keep if short==1
keep if !missing(production)
keep if production>0
bysort id (t): drop if _N == 1
  
gl a 	fertherd dealerdens govinpdensd farmsize ihs_rwagecashpc ihs_rofsecashpc ihs_rnonlcashpc ///
		litrate hhsize nasset livestock	cereals rootubs grainlg ///
		oilseed frutveg trecrop indcrop roadensity distmarket	///
		seedmarket pesticides hirlmarket agrocredit
		
foreach v in $a {

egen m_`v' = mean(`v'),by(id)

}

svyset cl [pweight = cpw], strata(strata) vce(linearized) singleunit(scaled)

gl x 	agehead i.female litrate hhsize nasset livestock						///
		i.cereals i.rootubs i.grainlg i.oilseed i.frutveg i.trecrop i.indcrop	///
		i.seedmarket i.pesticides i.hirlmarket i.agrocredit i.rural i.t
*
gl m 	m_fertherd m_dealerdens m_govinpdensd m_farmsize ///
		m_ihs_rwagecashpc m_ihs_rofsecashpc m_ihs_rnonlcashpc 					///
		m_litrate m_hhsize m_nasset m_livestock	m_cereals m_rootubs m_grainlg 	///
		m_oilseed m_frutveg m_trecrop m_indcrop c.m_roadensity##c.m_roadensity m_distmarket		///
		m_seedmarket m_pesticides m_hirlmarket m_agrocredit

gl w 	dealerdens i.govinpdensd farmsize 		///
		ihs_rwagecashpc ihs_rofsecashpc ihs_rnonlcashpc c.roadensity##c.roadensity distmarket i.favzone

qui svy: probit fertilizer fertherd $w $x $m
predict y
sum y,meanonly
local cmean = r(mean)

lab var fertherd "Share of peers buying"
qui margins if e(sample), dydx(fertherd) vce(unconditional) post
nlcom	(fertherd:		_b[fertherd]), post	
est store nig_1
		
outreg2 using "$tables/Table10.doc", dec(3) adec(3) label ctitle(NIG:11-16) ///
	addstat("Fertilizer market participation", 		`cmean') ///
	addtext(Year FE, YES, Location FE, YES, Other controls, YES) alpha(0.01, 0.05) ///
	symbol(***, **) nodepvar	
	
*----------------------------------	2019 Only ----------------------------------

use "$main/NigPanel.dta",clear
keep if t==4
keep if SSP
keep if !missing(production)
keep if production>0

svyset clust [pweight = weight], strata(strata) vce(linearized) singleunit(scaled)

gl x 	agehead i.female litrate hhsize nasset livestock						///
		i.cereals i.rootubs i.grainlg i.oilseed i.frutveg i.trecrop i.indcrop	///
		i.seedmarket i.pesticides i.hirlmarket i.agrocredit i.rural

gl w 	dealerdens i.govinpdensd farmsize 		///
		ihs_rwagecashpc ihs_rofsecashpc ihs_rnonlcashpc roadensity distmarket i.favzone

qui svy: probit fertilizer fertherd $w $x
predict y
sum y,meanonly
local cmean = r(mean)

lab var fertherd "Share of peers buying"
qui margins if e(sample), dydx(fertherd) vce(unconditional) post
nlcom	(fertherd:		_b[fertherd]), post	
est store nig_2
	
outreg2 using "$tables/Table10A.doc", dec(3) adec(3) label ctitle(NIG:2019) ///
	addstat("Fertilizer market participation", 		`cmean') ///
	addtext(Year FE, YES, Location FE, YES, Other controls, YES) alpha(0.01, 0.05) ///
	symbol(***, **) nodepvar	

*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

	
/*

			TANZANIA

		   (2015 & 2020)
*/

use "$main/TanPanel.dta",clear
keep if SSP
keep if short==1
keep if !missing(production)
keep if production>0
bysort id (t): drop if _N == 1

gl a 	fertherd dealerdens govinpdensd farmsize ihs_rwagecashpc ihs_rofsecashpc ihs_rnonlcashpc ///
		litrate hhsize nasset livestock	cereals rootubs grainlg ///
		oilseed frutveg trecrop indcrop roadensity distmarket	///
		seedmarket pesticides hirlmarket agrocredit
		
foreach v in $a {

egen m_`v' = mean(`v'),by(id)

}

svyset cl [pweight = cpw], strata(strata) vce(linearized) singleunit(scaled)

gl x 	agehead i.female litrate hhsize nasset livestock						///
		i.cereals i.rootubs i.grainlg i.oilseed i.frutveg i.trecrop i.indcrop	///
		i.seedmarket i.pesticides i.hirlmarket i.agrocredit i.rural i.t
		
gl m 	c.m_fertherd##c.m_fertherd m_dealerdens m_govinpdensd m_farmsize ///
		m_ihs_rwagecashpc m_ihs_rofsecashpc m_ihs_rnonlcashpc 					///
		m_litrate m_hhsize m_nasset m_livestock	m_cereals m_rootubs m_grainlg 	///
		m_oilseed m_frutveg m_trecrop m_indcrop m_roadensity m_distmarket		///
		m_seedmarket m_pesticides m_hirlmarket m_agrocredit

gl w 	dealerdens i.govinpdensd farmsize 		///
		ihs_rwagecashpc ihs_rofsecashpc ihs_rnonlcashpc roadensity distmarket i.favzone

qui svy: probit fertilizer c.fertherd##c.fertherd $w $x $m
predict y
sum y,meanonly
local cmean = r(mean)

lab var fertherd "Share of peers buying"
qui margins if e(sample), dydx(fertherd) vce(unconditional) post
nlcom	(fertherd:		_b[fertherd]), post
est store tan_1
		
outreg2 using "$tables/Table10.doc", dec(3) adec(3) label ctitle(TAN:15-20) ///
	addstat("Fertilizer market participation", 		`cmean') ///
	addtext(Year FE, YES, Location FE, YES, Other controls, YES) alpha(0.01, 0.05) ///
	symbol(***, **) nodepvar	
	
*-------------------------------- 2009, 2011 & 2013 ----------------------------

use "$main/TanPanel.dta",clear
keep if SSP
keep if longp==1
keep if !missing(production)
keep if production>0
bysort id (t): drop if _N == 1
  
gl a 	fertherd dealerdens govinpdensd farmsize ihs_rwagecashpc ihs_rofsecashpc ihs_rnonlcashpc ///
		litrate hhsize nasset livestock	cereals rootubs grainlg ///
		oilseed frutveg trecrop indcrop roadensity distmarket	///
		seedmarket pesticides hirlmarket agrocredit
		
foreach v in $a {

egen m_`v' = mean(`v'),by(id)

}

svyset cl [pweight = cpw], strata(strata) vce(linearized) singleunit(scaled)

gl x 	agehead i.female litrate hhsize nasset livestock						///
		i.cereals i.rootubs i.grainlg i.oilseed i.frutveg i.trecrop i.indcrop	///
		i.seedmarket i.pesticides i.hirlmarket i.agrocredit i.rural i.t 
*
gl m 	c.m_fertherd##c.m_fertherd m_dealerdens m_govinpdensd m_farmsize ///
		m_ihs_rwagecashpc m_ihs_rofsecashpc m_ihs_rnonlcashpc 					///
		m_litrate m_hhsize m_nasset m_livestock	m_cereals m_rootubs m_grainlg 	///
		m_oilseed m_frutveg m_trecrop m_indcrop m_roadensity m_distmarket		///
		m_seedmarket m_pesticides m_hirlmarket m_agrocredit

gl w 	dealerdens i.govinpdensd farmsize 		///
		ihs_rwagecashpc ihs_rofsecashpc ihs_rnonlcashpc roadensity distmarket i.favzone
*
qui svy: probit fertilizer c.fertherd##c.fertherd $w $x $m
predict y
sum y,meanonly
local cmean = r(mean)

lab var fertherd "Share of peers buying"
qui margins if e(sample), dydx(fertherd) vce(unconditional) post
nlcom	(fertherd:		_b[fertherd]), post
est store tan_2
		
outreg2 using "$tables/Table10A.doc", dec(3) adec(3) label ctitle(TAN:09-13) ///
	addstat("Fertilizer market participation", 		`cmean') ///
	addtext(Year FE, YES, Location FE, YES, Other controls, YES) alpha(0.01, 0.05) ///
	symbol(***, **) nodepvar	
*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

	
/*

			UGANDA

		  (2016 & 2020)
*/

use "$main/UgaPanel.dta",clear
keep if SSP
keep if short==1
keep if !missing(production)
keep if production>0
bysort id (t): drop if _N == 1

gl a 	fertherd dealerdens govinpdensd farmsize ihs_rwagecashpc ihs_rofsecashpc ihs_rnonlcashpc ///
		litrate hhsize nasset livestock	cereals rootubs grainlg ///
		oilseed frutveg trecrop indcrop roadensity distmarket	///
		seedmarket pesticides hirlmarket agrocredit
		
foreach v in $a {

egen m_`v' = mean(`v'),by(id)

}

svyset cl [pweight = cpw], strata(strata) vce(linearized) singleunit(scaled)

gl x 	agehead i.female litrate hhsize nasset livestock						///
		i.cereals i.rootubs i.grainlg i.oilseed i.frutveg i.trecrop i.indcrop	///
		i.seedmarket i.pesticides i.hirlmarket i.agrocredit i.rural i.t
	
gl m 	m_fertherd m_dealerdens m_govinpdensd m_farmsize ///
		m_ihs_rwagecashpc m_ihs_rofsecashpc m_ihs_rnonlcashpc 					///
		m_litrate m_hhsize m_nasset m_livestock	m_cereals m_rootubs m_grainlg 	///
		m_oilseed m_frutveg m_trecrop m_indcrop m_roadensity c.m_distmarket##c.m_distmarket		///
		m_seedmarket m_pesticides m_hirlmarket m_agrocredit

gl w 	dealerdens i.govinpdensd farmsize 		///
		ihs_rwagecashpc ihs_rofsecashpc ihs_rnonlcashpc roadensity c.distmarket##c.distmarket i.favzone

qui svy: probit fertilizer fertherd $w $x $m
predict y
sum y,meanonly
local cmean = r(mean)

lab var fertherd "Share of peers buying"
qui margins if e(sample), dydx(fertherd) vce(unconditional) post
nlcom	(fertherd:		_b[fertherd]), post
est store uga_1
		
outreg2 using "$tables/Table10.doc", dec(3) adec(3) label ctitle(UGA:16-20) ///
	addstat("Fertilizer market participation", 		`cmean') ///
	addtext(Year FE, YES, Location FE, YES, Other controls, YES) alpha(0.01, 0.05) ///
	symbol(***, **) nodepvar	
	
*-------------------------------- 2010, 2012, 2014) ----------------------------

use "$main/UgaPanel.dta",clear
keep if SSP
keep if medip==1
keep if !missing(production)
keep if production>0
bysort id (t): drop if _N == 1

gl a 	fertherd dealerdens govinpdensd farmsize ihs_rwagecashpc ihs_rofsecashpc ihs_rnonlcashpc ///
		litrate hhsize nasset livestock	cereals rootubs grainlg ///
		oilseed frutveg trecrop indcrop roadensity distmarket	///
		seedmarket pesticides hirlmarket agrocredit
		
foreach v in $a {

egen m_`v' = mean(`v'),by(id)

}

svyset cl [pweight = cpw], strata(strata) vce(linearized) singleunit(scaled)

gl x 	agehead i.female litrate hhsize nasset livestock						///
		i.cereals i.rootubs i.grainlg i.oilseed i.frutveg i.trecrop i.indcrop	///
		i.seedmarket i.pesticides i.hirlmarket i.agrocredit i.rural i.t 
		
gl m 	m_fertherd c.m_dealerdens##c.m_dealerdens m_govinpdensd c.m_farmsize##c.m_farmsize ///
		m_ihs_rwagecashpc m_ihs_rofsecashpc m_ihs_rnonlcashpc 					///
		m_litrate m_hhsize m_nasset m_livestock	m_cereals m_rootubs m_grainlg 	///
		m_oilseed m_frutveg m_trecrop m_indcrop m_roadensity m_distmarket		///
		m_seedmarket m_pesticides m_hirlmarket m_agrocredit

gl w 	c.dealerdens##c.dealerdens i.govinpdensd c.farmsize##c.farmsize 		///
		ihs_rwagecashpc ihs_rofsecashpc ihs_rnonlcashpc roadensity distmarket i.favzone
		
qui svy: probit fertilizer fertherd $w $x $m
predict y
sum y,meanonly
local cmean = r(mean)

lab var fertherd "Share of peers buying"
qui margins if e(sample), dydx(fertherd) vce(unconditional) post
nlcom	(fertherd:		_b[fertherd]), post
est store uga_2	
		
outreg2 using "$tables/Table10A.doc", dec(3) adec(3) label ctitle(UGA:10-14) ///
	addstat("Fertilizer market participation", 		`cmean') ///
	addtext(Year FE, YES, Location FE, YES, Other controls, YES) alpha(0.01, 0.05) ///
	symbol(***, **) nodepvar	

*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

	
/*

			ETHIOPIA

		(2012, 2014 & 2016)
*/

use "$main/EthPanel.dta",clear
keep if SSP
keep if longp==1
keep if !missing(production)
keep if production>0
bysort id (t): drop if _N == 1

gl a 	fertherd dealerdens govinpdensd farmsize ihs_rwagecashpc ihs_rofsecashpc ihs_rnonlcashpc ///
		litrate hhsize nasset livestock	cereals rootubs grainlg ///
		oilseed frutveg trecrop indcrop roadensity distmarket	///
		seedmarket pesticides hirlmarket agrocredit
		
foreach v in $a {

egen m_`v' = mean(`v'),by(id)

}

svyset cl [pweight = cpw], strata(strata) vce(linearized) singleunit(scaled)

gl x 	agehead i.female litrate hhsize nasset livestock						///
		i.cereals i.rootubs i.grainlg i.oilseed i.frutveg i.trecrop i.indcrop	///
		i.seedmarket i.pesticides i.hirlmarket i.agrocredit i.t i.rural
	
gl m 	c.m_fertherd##c.m_fertherd m_dealerdens m_govinpdensd c.m_farmsize##c.m_farmsize ///
		m_ihs_rwagecashpc m_ihs_rofsecashpc m_ihs_rnonlcashpc 					///
		m_litrate m_hhsize m_nasset m_livestock	m_cereals m_rootubs m_grainlg 	///
		m_oilseed m_frutveg m_trecrop m_indcrop m_roadensity m_distmarket		///
		m_seedmarket m_pesticides m_hirlmarket m_agrocredit

gl w 	dealerdens i.govinpdensd c.farmsize##c.farmsize		///
		ihs_rwagecashpc ihs_rofsecashpc ihs_rnonlcashpc roadensity distmarket i.favzone

qui svy: probit fertilizer c.fertherd##c.fertherd $w $x $m
predict y
sum y,meanonly
local cmean = r(mean)

lab var fertherd "Share of peers buying"
qui margins if e(sample), dydx(fertherd) vce(unconditional) post
nlcom	(fertherd:		_b[fertherd]), post
est store eth_1
		
outreg2 using "$tables/Table10.doc", dec(3) adec(3) label ctitle(ETH:12-16) ///
	addstat("Fertilizer market participation", 		`cmean') ///
	addtext(Year FE, YES, Location FE, YES, Other controls, YES) alpha(0.01, 0.05) ///
	symbol(***, **) nodepvar		
*-------------------------------- 	2019 Only		----------------------------
	
use "$main/EthPanel.dta",clear
keep if t==4
keep if SSP
keep if !missing(production)
keep if production>0
	
gl x 	agehead i.female litrate hhsize nasset livestock						///
		i.cereals i.rootubs i.grainlg i.oilseed i.frutveg i.trecrop i.indcrop	///
		i.seedmarket i.pesticides i.hirlmarket i.agrocredit i.rural 

gl w 	c.dealerdens##c.dealerdens i.govinpdensd farmsize 		///
		ihs_rwagecashpc ihs_rofsecashpc ihs_rnonlcashpc c.roadensity##c.roadensity c.distmarket##c.distmarket i.favzone

qui svy: probit fertilizer fertherd $w $x
predict y
sum y,meanonly
local cmean = r(mean)

lab var fertherd "Share of peers buying"
qui margins if e(sample), dydx(fertherd) vce(unconditional) post
nlcom	(fertherd:		_b[fertherd]), post
est store eth_2
		
outreg2 using "$tables/Table10A.doc", dec(3) adec(3) label ctitle(ETH:2019) ///
	addstat("Fertilizer market participation", 		`cmean') ///
	addtext(Year FE, NO, Location FE, YES, Other controls, YES) alpha(0.01, 0.05) ///
	symbol(***, **) nodepvar		
*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

	
/*

			MALAWI

	(2011, 2013, 2016 & 2019)
*/

use "$main/MalPanel.dta",clear
keep if SSP
keep if !missing(production)
keep if production>0
bysort id (t): drop if _N == 1
  
gl a 	fertherd dealerdens govinpdensd farmsize ihs_rwagecashpc ihs_rofsecashpc ihs_rnonlcashpc ///
		litrate hhsize nasset livestock	cereals rootubs grainlg ///
		oilseed frutveg trecrop indcrop roadensity distmarket	///
		seedmarket pesticides hirlmarket agrocredit
		
foreach v in $a {

egen m_`v' = mean(`v'),by(id)

}

svyset cl [pweight = cpw], strata(strata) vce(linearized) singleunit(scaled)

gl x 	agehead i.female litrate hhsize nasset livestock						///
		i.cereals i.rootubs i.grainlg i.oilseed i.frutveg i.trecrop i.indcrop	///
		i.seedmarket i.pesticides i.hirlmarket i.agrocredit i.t i.rural
*

gl m 	m_fertherd m_dealerdens m_govinpdensd m_farmsize ///
		m_ihs_rwagecashpc m_ihs_rofsecashpc m_ihs_rnonlcashpc 					///
		m_litrate m_hhsize m_nasset m_livestock	m_cereals m_rootubs m_grainlg 	///
		m_oilseed m_frutveg m_trecrop m_indcrop m_roadensity m_distmarket		///
		m_seedmarket m_pesticides m_hirlmarket m_agrocredit

gl w 	dealerdens i.govinpdensd farmsize 		///
		ihs_rwagecashpc ihs_rofsecashpc ihs_rnonlcashpc roadensity distmarket i.favzone

qui svy: probit fertilizer fertherd $w $x $m
predict y
sum y,meanonly
local cmean = r(mean)

lab var fertherd "Share of peers buying"
qui margins if e(sample), dydx(fertherd) vce(unconditional) post
nlcom	(fertherd:		_b[fertherd]), post
est store mal_1
		
outreg2 using "$tables/Table10.doc", dec(3) adec(3) label ctitle(MAL:11-19) ///
	addstat("Fertilizer market participation", 		`cmean') ///
	addtext(Year FE, YES, Location FE, YES, Other controls, YES) alpha(0.01, 0.05) ///
	symbol(***, **) nodepvar

*-------------------------------- 	2016 & 2019		----------------------------

use "$main/MalPanel.dta",clear
keep if SSP
keep if short==1
keep if !missing(production)
keep if production>0
bysort id (t): drop if _N == 1
  
gl a 	fertherd dealerdens govinpdensd farmsize ihs_rwagecashpc ihs_rofsecashpc ihs_rnonlcashpc ///
		litrate hhsize nasset livestock	cereals rootubs grainlg ///
		oilseed frutveg trecrop indcrop roadensity distmarket	///
		seedmarket pesticides hirlmarket agrocredit
		
foreach v in $a {

egen m_`v' = mean(`v'),by(id)

}

svyset cl [pweight = cpw], strata(strata) vce(linearized) singleunit(scaled)

gl x 	agehead i.female litrate hhsize nasset livestock						///
		i.cereals i.rootubs i.grainlg i.oilseed i.frutveg i.trecrop i.indcrop	///
		i.seedmarket i.pesticides i.hirlmarket i.agrocredit i.rural i.t 

gl m 	m_fertherd c.m_dealerdens##c.m_dealerdens m_govinpdensd m_farmsize ///
		m_ihs_rwagecashpc m_ihs_rofsecashpc m_ihs_rnonlcashpc 					///
		m_litrate m_hhsize m_nasset m_livestock	m_cereals m_rootubs m_grainlg 	///
		m_oilseed m_frutveg m_trecrop m_indcrop c.m_roadensity##c.m_roadensity m_distmarket		///
		m_seedmarket m_pesticides m_hirlmarket m_agrocredit

gl w 	c.dealerdens##c.dealerdens i.govinpdensd farmsize 		///
		ihs_rwagecashpc ihs_rofsecashpc ihs_rnonlcashpc c.roadensity##c.roadensity distmarket i.favzone

qui svy: probit fertilizer fertherd $w $x $m
predict y
sum y,meanonly
local cmean = r(mean)

lab var fertherd "Share of peers buying"
qui margins if e(sample), dydx(fertherd) vce(unconditional) post
nlcom	(fertherd:		_b[fertherd]), post
est store mal_2
		
outreg2 using "$tables/Table10A.doc", dec(3) adec(3) label ctitle(MAL:16-19) ///
	addstat("Fertilizer market participation", 		`cmean') ///
	addtext(Year FE, YES, Location FE, YES, Other controls, YES) alpha(0.01, 0.05) ///
	symbol(***, **) nodepvar
*

********************************************************************************

coefplot(gha_1,		ms(D)  mc(black) ciopts(recast(rcap) lc(black) lp(longdash)))	///
		(nig_1,		ms(D)  mc(black) ciopts(recast(rcap) lc(black) lp(longdash)))	///
		(tan_1,		ms(D)  mc(black) ciopts(recast(rcap) lc(black) lp(longdash)))	///
		(uga_1,		ms(D)  mc(black) ciopts(recast(rcap) lc(black) lp(longdash)))	///
		(eth_1,		ms(D)  mc(black) ciopts(recast(rcap) lc(black) lp(longdash)))	///
		(mal_1,		ms(D)  mc(black) ciopts(recast(rcap) lc(black) lp(longdash))),	///
		asequation swapnames xline(0, lp(solid) lc(red)) levels(95) legend(off) 	///
     eqren(gha_1 = "GHA (06-17)" 		///
           nig_1 = "NIG (11-16)"		///
		   tan_1 = "TAN (15-20)" 		///
           uga_1 = "UGA (16-20)"		///
           eth_1 = "ETH (12-16)"		///
           mal_1 = "MAL (11-19)")		///
   		   ylab(, nogrid) xlab(, nogrid) ///
		mlabel format(%9.2f) mlabpos(12) mlabcol(black) mlabgap(*2) grid(none)		///
		legend(off) xtitle("Marginal effect") xlab(-.20(.20).6, format(%9.1f) nogrid) ///
		title("{bf: (A)}" "{bf:Main regressions with most}" "{bf: recent panels/repeated cross-section}", size(medsmall)) name(graph1, replace) 
	
*-------------------------------------------------------------------------------

coefplot(gha_2,		ms(D)  mc(black) ciopts(recast(rcap) lc(black) lp(longdash)))	///
		(nig_2,		ms(D)  mc(black) ciopts(recast(rcap) lc(black) lp(longdash)))	///
		(tan_2,		ms(D)  mc(black) ciopts(recast(rcap) lc(black) lp(longdash)))	///
		(uga_2,		ms(D)  mc(black) ciopts(recast(rcap) lc(black) lp(longdash)))	///
		(eth_2,		ms(D)  mc(black) ciopts(recast(rcap) lc(black) lp(longdash)))	///
		(mal_2,		ms(D)  mc(black) ciopts(recast(rcap) lc(black) lp(longdash))),	///
		asequation swapnames xline(0, lp(solid) lc(red)) levels(95) legend(off) 	///
     eqren(gha_2 = "GHA (2017)" 		///
           nig_2 = "NIG (2019)"			///
		   tan_2 = "TAN (09-13)" 		///
           uga_2 = "UGA (10-14)"		///
           eth_2 = "ETH (2019)"			///
           mal_2 = "MAL (16-19)")		///
   		   ylab(, nogrid) xlab(, nogrid) ///
		mlabel format(%9.2f) mlabpos(12) mlabcol(black) mlabgap(*2) grid(none)		///
		legend(off) xtitle("Marginal effect") xlab(-.20(.20).6, format(%9.1f) nogrid)  ///
		title("{bf: (B)}" "{bf:Supplementary regressions with}" "{bf: other panels/recent cross-sections}", size(medsmall)) name(graph2, replace) 

graph combine graph1 graph2, imargin(tiny) col(2) iscale(1) 
graph export "$figures/FertPeer.tif", as(tif) name("Graph") replace

*------------------------------- PESTICIDES	------------------------------------

/*

			   GHANA

	(Repeated Cross-sections)
*/

use "$main/GhaData.dta",clear
drop if t==2
keep if SSP
keep if !missing(production)
keep if production>0

gl x 	agehead i.female litrate hhsize nasset livestock						///
		i.cereals i.rootubs i.grainlg i.oilseed i.frutveg i.trecrop i.indcrop	///
		i.seedmarket i.fertilizer i.hirlmarket i.agrocredit i.rural i.t
*
gl w 	c.dealerdens##c.dealerdens i.govinpdensd c.farmsize##c.farmsize ///
		ihs_rwagecashpc ihs_rofsecashpc ihs_rnonlcashpc c.roadensity##c.roadensity distmarket i.favzone

qui svy: probit pesticides pestherd $x $w
predict y
sum y,meanonly
local cmean = r(mean)

lab var pestherd "Share of peers buying"
qui margins if e(sample), dydx(pestherd) vce(unconditional) post
nlcom	(pestherd:		_b[pestherd]), post
est store gha_1
			
outreg2 using "$tables/Table11.doc", dec(3) adec(3) label ctitle(GHA:99-17) ///
	title("Peer effect on own pesticides market participation") ///
	addstat("Pesticides market participation", 		`cmean') ///
	addtext(Year FE, YES, Location FE, YES, Other controls, YES) alpha(0.01, 0.05) ///
	symbol(***, **) nodepvar replace	

	
*----------------------------------	2017 Only ----------------------------------

keep if t==5

gl x 	agehead i.female litrate hhsize nasset livestock						///
		i.cereals i.rootubs i.grainlg i.oilseed i.frutveg i.trecrop i.indcrop	///
		i.seedmarket i.fertilizer i.hirlmarket i.agrocredit i.rural

gl w 	c.dealerdens##c.dealerdens i.govinpdensd farmsize ///
		ihs_rwagecashpc ihs_rofsecashpc ihs_rnonlcashpc c.roadensity##c.roadensity c.distmarket##c.distmarket i.favzone

qui svy: probit pesticides pestherd $x $w
drop y
predict y
sum y,meanonly
local cmean = r(mean)

lab var pestherd "Share of peers buying"
qui margins if e(sample), dydx(pestherd) vce(unconditional) post
nlcom	(pestherd:		_b[pestherd]), post
est store gha_2
			
outreg2 using "$tables/Table11A.doc", dec(3) adec(3) label ctitle(GHA:2017) ///
	title("Peer effect on own pesticides market participation") ///
	addstat("Pesticides market participation", 		`cmean') ///
	addtext(Year FE, NO, Location FE, YES, Other controls, YES) alpha(0.01, 0.05) ///
	symbol(***, **) nodepvar replace	

*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
	
/*

			NIGERIA

		  (2011-2016)
*/

use "$main/NigPanel.dta",clear

keep if SSP
keep if short==1
keep if !missing(production)
keep if production>0
bysort id (t): drop if _N == 1

gl a 	pestherd dealerdens govinpdensd farmsize ihs_rwagecashpc ihs_rofsecashpc ihs_rnonlcashpc ///
		litrate hhsize nasset livestock	cereals rootubs grainlg ///
		oilseed frutveg trecrop indcrop roadensity distmarket	///
		seedmarket fertilizer hirlmarket agrocredit
		
foreach v in $a {

egen m_`v' = mean(`v'),by(id)

}

svyset cl [pweight = cpw], strata(strata) vce(linearized) singleunit(scaled)

gl x 	agehead i.female litrate hhsize nasset livestock						///
		i.cereals i.rootubs i.grainlg i.oilseed i.frutveg i.trecrop i.indcrop	///
		i.seedmarket i.fertilizer i.hirlmarket i.agrocredit i.rural
*
gl m 	m_pestherd m_dealerdens m_govinpdensd m_farmsize ///
		m_ihs_rwagecashpc m_ihs_rofsecashpc m_ihs_rnonlcashpc 					///
		m_litrate m_hhsize m_nasset m_livestock	m_cereals m_rootubs m_grainlg 	///
		m_oilseed m_frutveg m_trecrop m_indcrop c.m_roadensity##c.m_roadensity m_distmarket		///
		m_seedmarket m_fertilizer m_hirlmarket m_agrocredit

gl w 	dealerdens i.govinpdensd farmsize 		///
		ihs_rwagecashpc ihs_rofsecashpc ihs_rnonlcashpc c.roadensity##c.roadensity distmarket i.favzone

qui svy: probit pesticides pestherd $w $x $m
predict y
sum y,meanonly
local cmean = r(mean)

lab var pestherd "Share of peers buying"
qui margins if e(sample), dydx(pestherd) vce(unconditional) post
nlcom	(pestherd:		_b[pestherd]), post
est store nig_1
		
outreg2 using "$tables/Table11.doc", dec(3) adec(3) label ctitle(NIG:11-16) ///
	addstat("Pesticides market participation", 		`cmean') ///
	addtext(Year FE, YES, Location FE, YES, Other controls, YES) alpha(0.01, 0.05) ///
	symbol(***, **) nodepvar	
	
*----------------------------------	2019 Only ----------------------------------

use "$main/NigPanel.dta",clear
keep if t==4
keep if SSP
keep if !missing(production)
keep if production>0
  
svyset clust [pweight = weight], strata(strata) vce(linearized) singleunit(scaled)

gl x 	agehead i.female litrate hhsize nasset livestock						///
		i.cereals i.rootubs i.grainlg i.oilseed i.frutveg i.trecrop i.indcrop	///
		i.seedmarket i.fertilizer i.hirlmarket i.agrocredit i.rural

gl w 	dealerdens i.govinpdensd c.farmsize##c.farmsize 		///
		ihs_rwagecashpc ihs_rofsecashpc ihs_rnonlcashpc roadensity distmarket i.favzone

qui svy: probit pesticides pestherd $w $x
predict y
sum y,meanonly
local cmean = r(mean)

lab var pestherd "Share of peers buying"
qui margins if e(sample), dydx(pestherd) vce(unconditional) post
nlcom	(pestherd:		_b[pestherd]), post
est store nig_2
		
outreg2 using "$tables/Table11A.doc", dec(3) adec(3) label ctitle(NIG:2019) ///
	addstat("Pesticides market participation", 		`cmean') ///
	addtext(Year FE, YES, Location FE, YES, Other controls, YES) alpha(0.01, 0.05) ///
	symbol(***, **) nodepvar	
*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

	
/*

			TANZANIA

		   (2015 & 2020)
*/

use "$main/TanPanel.dta",clear
keep if SSP
keep if short==1
keep if !missing(production)
keep if production>0
bysort id (t): drop if _N == 1
  
gl a 	pestherd dealerdens govinpdensd farmsize ihs_rwagecashpc ihs_rofsecashpc ihs_rnonlcashpc ///
		litrate hhsize nasset livestock	cereals rootubs grainlg ///
		oilseed frutveg trecrop indcrop roadensity distmarket	///
		seedmarket fertilizer hirlmarket agrocredit
		
foreach v in $a {

egen m_`v' = mean(`v'),by(id)

}

svyset cl [pweight = cpw], strata(strata) vce(linearized) singleunit(scaled)

gl x 	agehead i.female litrate hhsize nasset livestock						///
		i.cereals i.rootubs i.grainlg i.oilseed i.frutveg i.trecrop i.indcrop	///
		i.seedmarket i.fertilizer i.hirlmarket i.agrocredit i.rural i.t 
*
gl m 	c.m_pestherd##c.m_pestherd m_dealerdens m_govinpdensd ///
		c.m_farmsize##c.m_farmsize m_ihs_rwagecashpc m_ihs_rofsecashpc m_ihs_rnonlcashpc ///
		m_litrate m_hhsize m_nasset m_livestock	m_cereals m_rootubs m_grainlg 	///
		m_oilseed m_frutveg m_trecrop m_indcrop m_roadensity m_distmarket		///
		m_seedmarket m_fertilizer m_hirlmarket m_agrocredit

gl w 	dealerdens i.govinpdensd c.farmsize##c.farmsize 		///
		ihs_rwagecashpc ihs_rofsecashpc ihs_rnonlcashpc roadensity distmarket i.favzone

qui svy: probit pesticides c.pestherd##c.pestherd $w $x $m
predict y
sum y,meanonly
local cmean = r(mean)

lab var pestherd "Share of peers buying"
qui margins if e(sample), dydx(pestherd) vce(unconditional) post
nlcom	(pestherd:		_b[pestherd]), post
est store tan_1
		
outreg2 using "$tables/Table11.doc", dec(3) adec(3) label ctitle(TAN:15-20) ///
	addstat("Pesticides market participation", 		`cmean') ///
	addtext(Year FE, YES, Location FE, YES, Other controls, YES) alpha(0.01, 0.05) ///
	symbol(***, **) nodepvar	
	
*-------------------------------- 2009, 2011 & 2013 ----------------------------

use "$main/TanPanel.dta",clear
keep if SSP
keep if longp==1
keep if !missing(production)
keep if production>0
bysort id (t): drop if _N == 1

gl a 	dealerdens govinpdensd farmsize ihs_rwagecashpc ihs_rofsecashpc ihs_rnonlcashpc ///
		litrate hhsize nasset livestock	cereals rootubs grainlg ///
		oilseed frutveg trecrop indcrop roadensity distmarket	///
		seedmarket fertilizer hirlmarket agrocredit
		
foreach v in $a {

egen m_`v' = mean(`v'),by(id)

}

svyset cl [pweight = cpw], strata(strata) vce(linearized) singleunit(scaled)

gl x 	agehead i.female litrate hhsize nasset livestock						///
		i.cereals i.rootubs i.grainlg i.oilseed i.frutveg i.trecrop i.indcrop	///
		i.seedmarket i.fertilizer i.hirlmarket i.agrocredit i.rural i.t 
*
gl m 	m_dealerdens m_govinpdensd m_farmsize ///
		m_ihs_rwagecashpc m_ihs_rofsecashpc m_ihs_rnonlcashpc 					///
		m_litrate m_hhsize m_nasset m_livestock	m_cereals m_rootubs m_grainlg 	///
		m_oilseed m_frutveg m_trecrop m_indcrop m_roadensity m_distmarket		///
		m_seedmarket m_fertilizer m_hirlmarket m_agrocredit

gl w 	dealerdens i.govinpdensd farmsize 		///
		ihs_rwagecashpc ihs_rofsecashpc ihs_rnonlcashpc roadensity distmarket i.favzone

qui svy: probit pesticides pestherd $w $x $m
predict y
sum y,meanonly
local cmean = r(mean)

lab var pestherd "Share of peers buying"
qui margins if e(sample), dydx(pestherd) vce(unconditional) post
nlcom	(pestherd:		_b[pestherd]), post
est store tan_2
		
outreg2 using "$tables/Table11A.doc", dec(3) adec(3) label ctitle(TAN:09-13) ///
	addstat("Pesticides market participation", 		`cmean') ///
	addtext(Year FE, YES, Location FE, YES, Other controls, YES) alpha(0.01, 0.05) ///
	symbol(***, **) nodepvar	

*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

	
/*

			UGANDA

		  (2016 & 2020)
*/

use "$main/UgaPanel.dta",clear
keep if SSP
keep if short==1
keep if !missing(production)
keep if production>0
bysort id (t): drop if _N == 1
  
gl a 	pestherd dealerdens govinpdensd farmsize ihs_rwagecashpc ihs_rofsecashpc ihs_rnonlcashpc ///
		litrate hhsize nasset livestock	cereals rootubs grainlg ///
		oilseed frutveg trecrop indcrop roadensity distmarket	///
		seedmarket fertilizer hirlmarket agrocredit
		
foreach v in $a {

egen m_`v' = mean(`v'),by(id)

}

svyset cl [pweight = cpw], strata(strata) vce(linearized) singleunit(scaled)

gl x 	agehead i.female litrate hhsize nasset livestock						///
		i.cereals i.rootubs i.grainlg i.oilseed i.frutveg i.trecrop i.indcrop	///
		i.seedmarket i.fertilizer i.hirlmarket i.agrocredit i.rural i.t 
	
gl m 	c.m_pestherd##c.m_pestherd c.m_dealerdens##c.m_dealerdens m_govinpdensd m_farmsize ///
		m_ihs_rwagecashpc m_ihs_rofsecashpc m_ihs_rnonlcashpc 					///
		m_litrate m_hhsize m_nasset m_livestock	m_cereals m_rootubs m_grainlg 	///
		m_oilseed m_frutveg m_trecrop m_indcrop m_roadensity m_distmarket		///
		m_seedmarket m_fertilizer m_hirlmarket m_agrocredit

gl w 	c.dealerdens##c.dealerdens  i.govinpdensd farmsize 		///
		ihs_rwagecashpc ihs_rofsecashpc ihs_rnonlcashpc roadensity distmarket i.favzone

qui svy: probit pesticides c.pestherd##c.pestherd $w $x $m
predict y
sum y,meanonly
local cmean = r(mean)

lab var pestherd "Share of peers buying"
qui margins if e(sample), dydx(pestherd) vce(unconditional) post
nlcom	(pestherd:		_b[pestherd]), post
est store uga_1
		
outreg2 using "$tables/Table11.doc", dec(3) adec(3) label ctitle(UGA:16-20) ///
	addstat("Pesticides market participation", 		`cmean') ///
	addtext(Year FE, YES, Location FE, YES, Other controls, YES) alpha(0.01, 0.05) ///
	symbol(***, **) nodepvar	
	
*-------------------------------- 2010, 2012, 2014) ----------------------------

use "$main/UgaPanel.dta",clear
keep if SSP
keep if medip==1
keep if !missing(production)
keep if production>0
bysort id (t): drop if _N == 1

gl a 	pestherd dealerdens govinpdensd farmsize ihs_rwagecashpc ihs_rofsecashpc ihs_rnonlcashpc ///
		litrate hhsize nasset livestock	cereals rootubs grainlg ///
		oilseed frutveg trecrop indcrop roadensity distmarket	///
		seedmarket fertilizer hirlmarket agrocredit
		
foreach v in $a {

egen m_`v' = mean(`v'),by(id)

}

svyset cl [pweight = cpw], strata(strata) vce(linearized) singleunit(scaled)

gl x 	agehead i.female litrate hhsize nasset livestock						///
		i.cereals i.rootubs i.grainlg i.oilseed i.frutveg i.trecrop i.indcrop	///
		i.seedmarket i.fertilizer i.hirlmarket i.agrocredit i.rural i.t 
		
gl m 	m_pestherd c.m_dealerdens##c.m_dealerdens m_govinpdensd m_farmsize ///
		m_ihs_rwagecashpc m_ihs_rofsecashpc m_ihs_rnonlcashpc 					///
		m_litrate m_hhsize m_nasset m_livestock	m_cereals m_rootubs m_grainlg 	///
		m_oilseed m_frutveg m_trecrop m_indcrop m_roadensity m_distmarket		///
		m_seedmarket m_fertilizer m_hirlmarket m_agrocredit

gl w 	c.dealerdens##c.dealerdens  i.govinpdensd farmsize 		///
		ihs_rwagecashpc ihs_rofsecashpc ihs_rnonlcashpc roadensity distmarket i.favzone
		
qui svy: probit pesticides pestherd $w $x $m
predict y
sum y,meanonly
local cmean = r(mean)

lab var pestherd "Share of peers buying"
qui margins if e(sample), dydx(pestherd) vce(unconditional) post
nlcom	(pestherd:		_b[pestherd]), post
est store uga_2	
		
outreg2 using "$tables/Table11A.doc", dec(3) adec(3) label ctitle(UGA:10-14) ///
	addstat("Pesticides market participation", 		`cmean') ///
	addtext(Year FE, YES, Location FE, YES, Other controls, YES) alpha(0.01, 0.05) ///
	symbol(***, **) nodepvar	

*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

	
/*

			ETHIOPIA

		(2012, 2014 & 2016)
*/

use "$main/EthPanel.dta",clear
keep if SSP
keep if longp==1
keep if !missing(production)
keep if production>0
bysort id (t): drop if _N == 1

gl a 	pestherd dealerdens govinpdensd farmsize ihs_rwagecashpc ihs_rofsecashpc ihs_rnonlcashpc ///
		litrate hhsize nasset livestock	cereals rootubs grainlg ///
		oilseed frutveg trecrop indcrop roadensity distmarket	///
		seedmarket fertilizer hirlmarket agrocredit
		
foreach v in $a {

egen m_`v' = mean(`v'),by(id)

}

svyset cl [pweight = cpw], strata(strata) vce(linearized) singleunit(scaled)

gl x 	agehead i.female litrate hhsize nasset livestock						///
		i.cereals i.rootubs i.grainlg i.oilseed i.frutveg i.trecrop i.indcrop	///
		i.seedmarket i.fertilizer i.hirlmarket i.agrocredit i.rural i.t 
	
gl m 	c.m_pestherd##c.m_pestherd m_dealerdens m_govinpdensd c.m_farmsize##c.m_farmsize ///
		m_ihs_rwagecashpc m_ihs_rofsecashpc m_ihs_rnonlcashpc 					///
		m_litrate m_hhsize m_nasset m_livestock	m_cereals m_rootubs m_grainlg 	///
		m_oilseed m_frutveg m_trecrop m_indcrop m_roadensity m_distmarket		///
		m_seedmarket m_fertilizer m_hirlmarket m_agrocredit

gl w 	dealerdens i.govinpdensd c.farmsize##c.farmsize		///
		ihs_rwagecashpc ihs_rofsecashpc ihs_rnonlcashpc roadensity distmarket i.favzone

qui svy: probit pesticides c.pestherd##c.pestherd $w $x $m
predict y
sum y,meanonly
local cmean = r(mean)

lab var pestherd "Share of peers buying"
qui margins if e(sample), dydx(pestherd) vce(unconditional) post
nlcom	(pestherd:		_b[pestherd]), post
est store eth_1
		
outreg2 using "$tables/Table11.doc", dec(3) adec(3) label ctitle(ETH:12-16) ///
	addstat("Pesticides market participation", 		`cmean') ///
	addtext(Year FE, YES, Location FE, YES, Other controls, YES) alpha(0.01, 0.05) ///
	symbol(***, **) nodepvar		
	
*-------------------------------- 	2019 Only		----------------------------
	
use "$main/EthPanel.dta",clear
keep if t==4
keep if SSP
keep if !missing(production)
keep if production>0

gl x 	agehead i.female litrate hhsize nasset livestock						///
		i.cereals i.rootubs i.grainlg i.oilseed i.frutveg i.trecrop i.indcrop	///
		i.seedmarket i.fertilizer i.hirlmarket i.agrocredit

gl w 	dealerdens i.govinpdensd c.farmsize##c.farmsize 		///
		ihs_rwagecashpc ihs_rofsecashpc ihs_rnonlcashpc roadensity distmarket i.favzone

qui svy: probit pesticides pestherd $w $x
predict y
sum y,meanonly
local cmean = r(mean)

lab var pestherd "Share of peers buying"
qui margins if e(sample), dydx(pestherd) vce(unconditional) post
nlcom	(pestherd:		_b[pestherd]), post
est store eth_2
		
outreg2 using "$tables/Table11A.doc", dec(3) adec(3) label ctitle(ETH:2019) ///
	addstat("Pesticides market participation", 		`cmean') ///
	addtext(Year FE, NO, Location FE, YES, Other controls, YES) alpha(0.01, 0.05) ///
	symbol(***, **) nodepvar		

*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

	
/*

			MALAWI

	(2011, 2013, 2016 & 2019)
*/

use "$main/MalPanel.dta",clear
keep if SSP
keep if !missing(production)
keep if production>0
bysort id (t): drop if _N == 1
  
gl a 	pestherd dealerdens govinpdensd farmsize ihs_rwagecashpc ihs_rofsecashpc ihs_rnonlcashpc ///
		litrate hhsize nasset livestock	cereals rootubs grainlg ///
		oilseed frutveg trecrop indcrop roadensity distmarket	///
		seedmarket fertilizer hirlmarket agrocredit
		
foreach v in $a {

egen m_`v' = mean(`v'),by(id)

}

svyset cl [pweight = cpw], strata(strata) vce(linearized) singleunit(scaled)

gl x 	agehead i.female litrate hhsize nasset livestock						///
		i.cereals i.rootubs i.grainlg i.oilseed i.frutveg i.trecrop i.indcrop	///
		i.seedmarket i.fertilizer i.hirlmarket i.agrocredit i.rural i.t 
*
gl m 	m_pestherd m_dealerdens m_govinpdensd c.m_farmsize##c.m_farmsize ///
		m_ihs_rwagecashpc m_ihs_rofsecashpc m_ihs_rnonlcashpc 					///
		m_litrate m_hhsize m_nasset m_livestock	m_cereals m_rootubs m_grainlg 	///
		m_oilseed m_frutveg m_trecrop m_indcrop m_roadensity m_distmarket		///
		m_seedmarket m_fertilizer m_hirlmarket m_agrocredit

gl w 	dealerdens i.govinpdensd c.farmsize##c.farmsize 		///
		ihs_rwagecashpc ihs_rofsecashpc ihs_rnonlcashpc roadensity distmarket i.favzone

qui svy: probit pesticides pestherd $w $x $m
predict y
sum y,meanonly
local cmean = r(mean)

lab var pestherd "Share of peers buying"
qui margins if e(sample), dydx(pestherd) vce(unconditional) post
nlcom	(pestherd:		_b[pestherd]), post
est store mal_1
		
outreg2 using "$tables/Table11.doc", dec(3) adec(3) label ctitle(MAL:11-19) ///
	addstat("Pesticides market participation", 		`cmean') ///
	addtext(Year FE, YES, Location FE, YES, Other controls, YES) alpha(0.01, 0.05) ///
	symbol(***, **) nodepvar	

*-------------------------------- 	2016 & 2019		----------------------------

use "$main/MalPanel.dta",clear
keep if SSP
keep if short==1
keep if !missing(production)
keep if production>0
bysort id (t): drop if _N == 1

gl a 	pestherd dealerdens govinpdensd farmsize ihs_rwagecashpc ihs_rofsecashpc ihs_rnonlcashpc ///
		litrate hhsize nasset livestock	cereals rootubs grainlg ///
		oilseed frutveg trecrop indcrop roadensity distmarket	///
		seedmarket fertilizer hirlmarket agrocredit
		
foreach v in $a {

egen m_`v' = mean(`v'),by(id)

}

svyset cl [pweight = cpw], strata(strata) vce(linearized) singleunit(scaled)

gl x 	agehead i.female litrate hhsize nasset livestock						///
		i.cereals i.rootubs i.grainlg i.oilseed i.frutveg i.trecrop i.indcrop	///
		i.seedmarket i.fertilizer i.hirlmarket i.agrocredit i.rural i.t 

gl m 	m_pestherd m_dealerdens m_govinpdensd m_farmsize ///
		m_ihs_rwagecashpc m_ihs_rofsecashpc m_ihs_rnonlcashpc 					///
		m_litrate m_hhsize m_nasset m_livestock	m_cereals m_rootubs m_grainlg 	///
		m_oilseed m_frutveg m_trecrop m_indcrop m_roadensity m_distmarket		///
		m_seedmarket m_fertilizer m_hirlmarket m_agrocredit

gl w 	dealerdens i.govinpdensd farmsize 		///
		ihs_rwagecashpc ihs_rofsecashpc ihs_rnonlcashpc roadensity distmarket i.favzone

qui svy: probit pesticides pestherd $w $x $m
predict y
sum y,meanonly
local cmean = r(mean)

lab var pestherd "Share of peers buying"
qui margins if e(sample), dydx(pestherd) vce(unconditional) post
nlcom	(pestherd:		_b[pestherd]), post
est store mal_2
		
outreg2 using "$tables/Table11A.doc", dec(3) adec(3) label ctitle(MAL:16-19) ///
	addstat("Pesticides market participation", 		`cmean') ///
	addtext(Year FE, YES, Location FE, YES, Other controls, YES) alpha(0.01, 0.05) ///
	symbol(***, **) nodepvar	

********************************************************************************

coefplot(gha_1,		ms(D)  mc(black) ciopts(recast(rcap) lc(black) lp(longdash)))	///
		(nig_1,		ms(D)  mc(black) ciopts(recast(rcap) lc(black) lp(longdash)))	///
		(tan_1,		ms(D)  mc(black) ciopts(recast(rcap) lc(black) lp(longdash)))	///
		(uga_1,		ms(D)  mc(black) ciopts(recast(rcap) lc(black) lp(longdash)))	///
		(eth_1,		ms(D)  mc(black) ciopts(recast(rcap) lc(black) lp(longdash)))	///
		(mal_1,		ms(D)  mc(black) ciopts(recast(rcap) lc(black) lp(longdash))),	///
		asequation swapnames xline(0, lp(solid) lc(red)) levels(95) legend(off) 	///
     eqren(gha_1 = "GHA (06-17)" 		///
           nig_1 = "NIG (11-16)"		///
		   tan_1 = "TAN (15-20)" 		///
           uga_1 = "UGA (16-20)"		///
           eth_1 = "ETH (12-16)"		///
           mal_1 = "MAL (11-19)")		///
   		   ylab(, nogrid) xlab(, nogrid) ///
		mlabel format(%9.2f) mlabpos(12) mlabcol(black) mlabgap(*2) grid(none)		///
		legend(off) xtitle("Marginal effect") xlab(-.80(.40).8, format(%9.1f) nogrid) ///
		title("{bf: (A)}" "{bf:Main regressions with most}" "{bf: recent panels/repeated cross-section}", size(medsmall)) name(graph1, replace) 
	
*-------------------------------------------------------------------------------

coefplot(gha_2,		ms(D)  mc(black) ciopts(recast(rcap) lc(black) lp(longdash)))	///
		(nig_2,		ms(D)  mc(black) ciopts(recast(rcap) lc(black) lp(longdash)))	///
		(tan_2,		ms(D)  mc(black) ciopts(recast(rcap) lc(black) lp(longdash)))	///
		(uga_2,		ms(D)  mc(black) ciopts(recast(rcap) lc(black) lp(longdash)))	///
		(eth_2,		ms(D)  mc(black) ciopts(recast(rcap) lc(black) lp(longdash)))	///
		(mal_2,		ms(D)  mc(black) ciopts(recast(rcap) lc(black) lp(longdash))),	///
		asequation swapnames xline(0, lp(solid) lc(red)) levels(95) legend(off) 	///
     eqren(gha_2 = "GHA (2017)" 		///
           nig_2 = "NIG (2019)"			///
		   tan_2 = "TAN (09-13)" 		///
           uga_2 = "UGA (10-14)"		///
           eth_2 = "ETH (2019)"			///
           mal_2 = "MAL (16-19)")		///
   		   ylab(, nogrid) xlab(, nogrid) ///
		mlabel format(%9.2f) mlabpos(12) mlabcol(black) mlabgap(*2) grid(none)		///
		legend(off) xtitle("Marginal effect")  xlab(-.80(.40).8, format(%9.1f) nogrid) ///
		title("{bf: (B)}" "{bf:Supplementary regressions with}" "{bf: other panels/recent cross-sections}", size(medsmall)) name(graph2, replace) 

graph combine graph1 graph2, imargin(tiny) col(2) iscale(1) 
graph export "$figures/PestPeer.tif", as(tif) name("Graph") replace

********************************************************************************
*								OUTPUT MARKET								   *
********************************************************************************


*------------------------- EXTENSIVE & INTENSIVE MARGIN	------------------------

/*

			   GHANA

	(Repeated Cross-sections)
*/

use "$main/GhaData.dta",clear

keep if SSP
drop if t==2
keep if !missing(production)
keep if production>0

foreach i in wagecashsh ofsecashsh nonlcashsh {
	
replace `i' = 0 if `i' ==. & cci!=.

}

*------------------------- EXTENSIVE & INTENSIVE MARGIN	------------------------

gl x 	Lnrvharvest agehead i.female litrate hhsize nasset livestock			///
		i.cereals i.rootubs i.grainlg i.oilseed i.frutveg i.trecrop i.indcrop	///
		i.t i.rural

gl w1	c.traderdens##c.traderdens i.insbuydensd farmsize ///
		wagecashsh ofsecashsh nonlcashsh roadensity c.distmarket##c.distmarket i.favzone

gl w2	traderdens i.insbuydensd c.farmsize##c.farmsize ///
		wagecashsh ofsecashsh nonlcashsh roadensity distmarket i.favzone
*

qui svy: churdle exp rvalsalesT cherd $w2 $x, select(c.cherd##c.cherd $w1 $x) ll(0)
predict y, pr(0,.)
sum y,meanonly
local cmean = r(mean)

qui margins if e(sample), dydx(cherd) predict(pr(0,.)) vce(unconditional) post
lab var cherd "Proportion sold by peers"
nlcom	(cherd:		    _b[cherd]), post
est store gha_mp1
		
outreg2 using "$tables/Table12a.doc", dec(3) adec(3) label ctitle(GHA:12-17) ///
	title("Peer effect on own market participation") ///
	addstat("Market participation", 		`cmean') ///
	addtext(Year FE, YES, Location FE, YES, Other controls, YES) alpha(0.01, 0.05) ///
	symbol(***, **) nodepvar replace

*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

qui svy: churdle exp rvalsalesT cherd $w2 $x, select(c.cherd##c.cherd $w1 $x) ll(0)
drop y
predict y
sum y,meanonly
local cmean = r(mean)

qui margins if e(sample), dydx(cherd) vce(unconditional) post
lab var cherd "Proportion sold by peers"
nlcom	(cherd:		    _b[cherd]), post
est store gha_im1
			
outreg2 using "$tables/Table12b.doc", dec(0) adec(3) label ctitle(GHA:12-17) ///
	title("Peer effect on own value of sales") ///
	addstat("Mean value sold ($)", 		`cmean') ///
	addtext(Year FE, YES, Location FE, YES, Other controls, YES) alpha(0.01, 0.05) ///
	symbol(***, **) nodepvar replace		

*------------------------------- INTENSITY	------------------------------------

gl w	traderdens i.insbuydensd c.farmsize##c.farmsize ///
		wagecashsh ofsecashsh nonlcashsh roadensity distmarket i.favzone

qui svy: fracreg probit cci cherd $w $x
drop y
predict y
sum y,meanonly
local cmean = r(mean)

qui margins if e(sample), dydx(cherd) vce(unconditional) post
lab var cherd "Proportion sold by peers"
nlcom	(cherd:		    _b[cherd]), post
est store gha_in1
		
outreg2 using "$tables/Table12c.doc", dec(3) adec(3) label ctitle(GHA:12-17) ///
	title("Peer effect on own share of output sold") ///
	addstat("Mean proportion sold",	`cmean') ///
	addtext(Year FE, YES, Location FE, YES, Other controls, YES) alpha(0.01, 0.05) ///
	symbol(***, **) nodepvar replace		

********************************************************************************

/*
			  (2017)
*/

use "$main/GhaData.dta",clear
keep if t==5
keep if SSP
keep if !missing(production)
keep if production>0

foreach i in wagecashsh ofsecashsh nonlcashsh {
	
replace `i' = 0 if `i' ==. & cci!=.

}

*------------------------- EXTENSIVE & INTENSIVE MARGIN	------------------------

gl x 	Lnrvharvest agehead i.female litrate hhsize nasset livestock			///
		i.cereals i.rootubs i.grainlg i.oilseed i.frutveg i.trecrop i.indcrop	///
		i.rural

gl w1	traderdens i.insbuydensd farmsize ///
		wagecashsh ofsecashsh nonlcashsh roadensity distmarket i.favzone

gl w2	traderdens i.insbuydensd farmsize ///
		wagecashsh ofsecashsh nonlcashsh roadensity distmarket i.favzone

qui svy: churdle exp rvalsalesT cherd $w2 $x, select(cherd $w1 $x) ll(0)
predict y, pr(0,.)
sum y,meanonly
local cmean = r(mean)

lab var cherd "Proportion sold by peers"
qui margins if e(sample), dydx(cherd) predict(pr(0,.)) vce(unconditional) post
nlcom	(cherd:		    _b[cherd]), post
est store gha_mp2

			
outreg2 using "$tables/TableA12a.doc", dec(3) adec(3) label ctitle(GHA:2017) ///
	title("Peer effect on own market participation") ///
	addstat("Market participation", 		`cmean') ///
	addtext(Year FE, NO, Location FE, YES, Other controls, YES) alpha(0.01, 0.05) ///
	symbol(***, **) nodepvar replace	

*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

qui svy: churdle exp rvalsalesT cherd $w2 $x, select(cherd $w1 $x) ll(0)
drop y
predict y
sum y,meanonly
local cmean = r(mean)

lab var cherd "Proportion sold by peers"
qui margins if e(sample), dydx(cherd) vce(unconditional) post
nlcom	(cherd:		    _b[cherd]), post
est store gha_im2
			
outreg2 using "$tables/TableA12b.doc", dec(0) adec(3) label ctitle(GHA:2017) ///
	title("Peer effect on own value of sales") ///
	addstat("Mean value sold ($)", 		`cmean') ///
	addtext(Year FE, NO, Location FE, YES, Other controls, YES) alpha(0.01, 0.05) ///
	symbol(***, **) nodepvar replace		

*------------------------------- INTENSITY	------------------------------------

gl w	c.traderdens##c.traderdens i.insbuydensd c.farmsize##c.farmsize ///
		wagecashsh ofsecashsh nonlcashsh roadensity distmarket i.favzone

qui svy: fracreg probit cci cherd $w $x
drop y
predict y
sum y,meanonly
local cmean = r(mean)

lab var cherd "Proportion sold by peers"
qui margins if e(sample), dydx(cherd) vce(unconditional) post
nlcom	(cherd:		    _b[cherd]), post
est store gha_in2
		
outreg2 using "$tables/TableA12c.doc", dec(3) adec(3) label ctitle(GHA:2017) ///
	title("Peer effect on own share of output sold") ///
	addstat("Mean proportion sold",	`cmean') ///
	addtext(Year FE, NO, Location FE, YES, Other controls, YES) alpha(0.01, 0.05) ///
	symbol(***, **) nodepvar replace		

*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


/*

			NIGERIA

		  (2011-2016)
*/

use "$main/NigPanel.dta",clear

keep if SSP
keep if short==1
keep if !missing(production)
keep if production>0
bysort id (t): drop if _N == 1

foreach i in wagecashsh ofsecashsh nonlcashsh {
	
replace `i' = 0 if `i' ==. & cci!=.

}

gl a 	cherd traderdens insbuydensd farmsize wagecashsh ofsecashsh nonlcashsh ///
		Lnrvharvest litrate hhsize nasset livestock	cereals rootubs grainlg ///
		oilseed frutveg trecrop indcrop roadensity distmarket
		
foreach v in $a {

egen m_`v' = mean(`v'),by(id)

}

*------------------------- EXTENSIVE & INTENSIVE MARGIN	------------------------

gl x 	Lnrvharvest agehead i.female litrate hhsize nasset livestock			///
		i.cereals i.rootubs i.grainlg i.oilseed i.frutveg i.trecrop i.indcrop i.rural i.t 
		
gl m1 	m_cherd c.m_traderdens##c.m_traderdens m_insbuydensd m_farmsize ///
		m_wagecashsh m_ofsecashsh m_nonlcashsh m_Lnrvharvest m_litrate m_hhsize ///
		m_nasset m_livestock m_cereals m_rootubs m_grainlg m_oilseed ///
		m_frutveg m_trecrop m_indcrop c.m_roadensity##c.m_roadensity c.m_distmarket##c.m_distmarket

gl m2 	c.m_cherd##c.m_cherd m_traderdens m_insbuydensd m_farmsize ///
		m_wagecashsh m_ofsecashsh m_nonlcashsh m_Lnrvharvest m_litrate m_hhsize ///
		m_nasset m_livestock m_cereals m_rootubs m_grainlg m_oilseed ///
		m_frutveg m_trecrop m_indcrop c.m_roadensity##c.m_roadensity m_distmarket

gl w1	c.traderdens##c.traderdens i.insbuydensd farmsize ///
		wagecashsh ofsecashsh nonlcashsh c.roadensity##c.roadensity c.distmarket##c.distmarket i.favzone
		
gl w2	traderdens i.insbuydensd farmsize ///
		wagecashsh ofsecashsh nonlcashsh c.roadensity##c.roadensity distmarket i.favzone

qui svy: churdle exp rvalsalesT c.cherd##c.cherd $w2 $x $m2, select(cherd $w1 $x $m1) ll(0)
predict y, pr(0,.)
sum y,meanonly
local cmean = r(mean)

lab var cherd "Proportion sold by peers"
qui margins if e(sample), dydx(cherd) predict(pr(0,.)) vce(unconditional) post
nlcom	(cherd:		    _b[cherd]), post
est store nig_mp1
			
outreg2 using "$tables/Table12a.doc", dec(3) adec(3) label ctitle(NIG:11-16) ///
	addstat("Market participation", 		`cmean') ///
	addtext(Year FE, YES, Location FE, YES, Other controls, YES) alpha(0.01, 0.05) ///
	symbol(***, **) nodepvar	

*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

qui svy: churdle exp rvalsalesT c.cherd##c.cherd $w2 $x $m2, select(cherd $w1 $x $m1) ll(0)
drop y
predict y
sum y,meanonly
local cmean = r(mean)

lab var cherd "Proportion sold by peers"
qui margins if e(sample), dydx(cherd) vce(unconditional) post
nlcom	(cherd:		    _b[cherd]), post
est store nig_im1
			
outreg2 using "$tables/Table12b.doc", dec(0) adec(3) label ctitle(NIG:11-16) ///
	addstat("Mean value sold ($)", 		`cmean') ///
	addtext(Year FE, YES, Location FE, YES, Other controls, YES) alpha(0.01, 0.05) ///
	symbol(***, **) nodepvar		

*------------------------------- INTENSITY	------------------------------------

gl x 	Lnrvharvest agehead i.female litrate hhsize nasset livestock			///
		i.cereals i.rootubs i.grainlg i.oilseed i.frutveg i.trecrop i.indcrop i.rural i.t 
		
gl m 	m_cherd m_traderdens m_insbuydensd m_farmsize m_wagecashsh m_ofsecashsh m_nonlcashsh ///
		m_Lnrvharvest m_litrate m_hhsize m_nasset m_livestock m_cereals m_rootubs m_grainlg ///
		m_oilseed m_frutveg m_trecrop m_indcrop c.m_roadensity##c.m_roadensity m_distmarket
		
gl w 	traderdens i.insbuydensd farmsize ///
		wagecashsh ofsecashsh nonlcashsh c.roadensity##c.roadensity distmarket i.favzone

qui svy: fracreg probit cci cherd $w $x $m
drop y
predict y
sum y,meanonly
local cmean = r(mean)

lab var cherd "Proportion sold by peers"
qui margins if e(sample), dydx(cherd) vce(unconditional) post
nlcom	(cherd:		    _b[cherd]), post
est store nig_in1
		
outreg2 using "$tables/Table12c.doc", dec(3) adec(3) label ctitle(NIG:11-16) ///
	addstat("Mean proportion sold",	`cmean') ///
	addtext(Year FE, YES, Location FE, YES, Other controls, YES) alpha(0.01, 0.05) ///
	symbol(***, **) nodepvar		


********************************************************************************
/*

			NIGERIA

		     2019
*/

use "$main/NigPanel.dta",clear
keep if t==4
keep if SSP
keep if !missing(production)
keep if production>0

foreach i in wagecashsh ofsecashsh nonlcashsh {
	
replace `i' = 0 if `i' ==. & cci!=.

}

svyset clust [pweight = weight], strata(strata) vce(linearized) singleunit(scaled)

*------------------------- EXTENSIVE & INTENSIVE MARGIN	------------------------

gl x 	Lnrvharvest agehead i.female litrate hhsize nasset livestock			///
		i.cereals i.rootubs i.grainlg i.oilseed i.frutveg i.trecrop i.indcrop i.rural
		
gl w1	traderdens i.insbuydensd farmsize ///
		wagecashsh ofsecashsh nonlcashsh c.roadensity##c.roadensity distmarket i.favzone

gl w2	traderdens i.insbuydensd farmsize ///
		wagecashsh ofsecashsh nonlcashsh roadensity distmarket i.favzone
		
qui svy: churdle exp rvalsalesT cherd $w2 $x, select(c.cherd##c.cherd $w1 $x) ll(0)
predict y, pr(0,.)
sum y,meanonly
local cmean = r(mean)

lab var cherd "Proportion sold by peers"
qui margins if e(sample), dydx(cherd) predict(pr(0,.)) vce(unconditional) post
nlcom	(cherd:		    _b[cherd]), post
est store nig_mp2
			
outreg2 using "$tables/TableA12a.doc", dec(3) adec(3) label ctitle(NIG:2019) ///
	addstat("Market participation", 		`cmean') ///
	addtext(Year FE, NO, Location FE, YES, Other controls, YES) alpha(0.01, 0.05) ///
	symbol(***, **) nodepvar	

*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

qui svy: churdle exp rvalsalesT cherd $w2 $x, select(c.cherd##c.cherd $w1 $x) ll(0)
drop y
predict y
sum y,meanonly
local cmean = r(mean)

lab var cherd "Proportion sold by peers"
qui margins if e(sample), dydx(cherd) vce(unconditional) post
nlcom	(cherd:		    _b[cherd]), post
est store nig_im2
			
outreg2 using "$tables/TableA12b.doc", dec(0) adec(3) label ctitle(NIG:2019) ///
	addstat("Mean value sold ($)", 		`cmean') ///
	addtext(Year FE, NO, Location FE, YES, Other controls, YES) alpha(0.01, 0.05) ///
	symbol(***, **) nodepvar		

*------------------------------- INTENSITY	------------------------------------
		
gl x 	Lnrvharvest agehead i.female litrate hhsize nasset livestock			///
		i.cereals i.rootubs i.grainlg i.oilseed i.frutveg i.trecrop i.indcrop i.rural 
				
gl w	traderdens i.insbuydensd farmsize ///
		wagecashsh ofsecashsh nonlcashsh roadensity distmarket i.favzone

qui svy: fracreg probit cci cherd $w $x
drop y
predict y
sum y,meanonly
local cmean = r(mean)

lab var cherd "Proportion sold by peers"
qui margins if e(sample), dydx(cherd) vce(unconditional) post
nlcom	(cherd:		    _b[cherd]), post
est store nig_in2
		
outreg2 using "$tables/TableA12c.doc", dec(3) adec(3) label ctitle(NIG:2019) ///
	addstat("Mean proportion sold",	`cmean') ///
	addtext(Year FE, NO, Location FE, YES, Other controls, YES) alpha(0.01, 0.05) ///
	symbol(***, **) nodepvar		

*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

/*

			TANZANIA

		   (2015 & 2020)
*/

use "$main/TanPanel.dta",clear
keep if SSP
keep if short==1
keep if !missing(production)
keep if production>0
bysort id (t): drop if _N == 1

foreach i in wagecashsh ofsecashsh nonlcashsh {
	
replace `i' = 0 if `i' ==. & cci!=.

}

gl a 	cherd traderdens insbuydensd farmsize wagecashsh ofsecashsh nonlcashsh ///
		Lnrvharvest litrate hhsize nasset livestock	cereals rootubs grainlg ///
		oilseed frutveg trecrop indcrop roadensity distmarket
		
foreach v in $a {

egen m_`v' = mean(`v'),by(id)

}

*------------------------- EXTENSIVE & INTENSIVE MARGIN	------------------------

gl x 	Lnrvharvest agehead i.female litrate hhsize nasset livestock			///
		i.cereals i.rootubs i.grainlg i.oilseed i.frutveg i.trecrop i.indcrop i.rural i.t 
		
gl m1 	c.m_cherd##c.m_cherd c.m_traderdens##c.m_traderdens m_insbuydensd m_farmsize ///
		m_wagecashsh m_ofsecashsh m_nonlcashsh m_Lnrvharvest m_litrate m_hhsize ///
		m_nasset m_livestock m_cereals m_rootubs m_grainlg  ///
		m_oilseed m_frutveg m_trecrop m_indcrop m_roadensity m_distmarket

gl m2 	m_cherd m_traderdens m_insbuydensd c.m_farmsize##c.m_farmsize ///
		m_wagecashsh m_ofsecashsh m_nonlcashsh m_Lnrvharvest m_litrate m_hhsize ///
		m_nasset m_livestock m_cereals m_rootubs m_grainlg  ///
		m_oilseed m_frutveg m_trecrop m_indcrop m_roadensity m_distmarket
		
gl w1	c.traderdens##c.traderdens i.insbuydensd farmsize ///
		wagecashsh ofsecashsh nonlcashsh roadensity distmarket i.favzone
		
gl w2	traderdens i.insbuydensd c.farmsize##c.farmsize ///
		wagecashsh ofsecashsh nonlcashsh roadensity distmarket i.favzone

qui svy: churdle exp rvalsalesT cherd $w2 $x $m2, select(c.cherd##c.cherd $w1 $x $m1) ll(0)
predict y, pr(0,.)
sum y,meanonly
local cmean = r(mean)

lab var cherd "Proportion sold by peers"
qui margins if e(sample), dydx(cherd) predict(pr(0,.)) vce(unconditional) post
nlcom	(cherd:		    _b[cherd]), post
est store tan_mp1
		
outreg2 using "$tables/Table12a.doc", dec(3) adec(3) label ctitle(TAN:15-20) ///
	addstat("Market participation", 		`cmean') ///
	addtext(Year FE, YES, Location FE, YES, Other controls, YES) alpha(0.01, 0.05) ///
	symbol(***, **) nodepvar	

*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

qui svy: churdle exp rvalsalesT cherd $w2 $x $m2, select(c.cherd##c.cherd $w1 $x $m1) ll(0)
drop y
predict y
sum y,meanonly
local cmean = r(mean)

lab var cherd "Proportion sold by peers"
qui margins if e(sample), dydx(cherd) vce(unconditional) post
nlcom	(cherd:		    _b[cherd]), post
est store tan_im1
			
outreg2 using "$tables/Table12b.doc", dec(0) adec(3) label ctitle(TAN:15-20) ///
	addstat("Mean value sold ($)", 		`cmean') ///
	addtext(Year FE, YES, Location FE, YES, Other controls, YES) alpha(0.01, 0.05) ///
	symbol(***, **) nodepvar		

*------------------------------- INTENSITY	------------------------------------

gl x 	Lnrvharvest agehead i.female litrate hhsize nasset livestock			///
		i.cereals i.rootubs i.grainlg i.oilseed i.frutveg i.trecrop i.indcrop i.rural i.t 
		
gl m 	m_cherd m_traderdens m_insbuydensd m_farmsize m_wagecashsh m_ofsecashsh m_nonlcashsh ///
		m_Lnrvharvest m_litrate m_hhsize m_nasset m_livestock m_cereals m_rootubs m_grainlg ///
		m_oilseed m_frutveg m_trecrop m_indcrop m_roadensity m_distmarket
		
gl w	traderdens i.insbuydensd farmsize ///
		wagecashsh ofsecashsh nonlcashsh roadensity distmarket i.favzone

qui svy: fracreg probit cci cherd $w $x $m
drop y
predict y
sum y,meanonly
local cmean = r(mean)

lab var cherd "Proportion sold by peers"
qui margins if e(sample), dydx(cherd) vce(unconditional) post
nlcom	(cherd:		    _b[cherd]), post
est store tan_in1
		
outreg2 using "$tables/Table12c.doc", dec(3) adec(3) label ctitle(TAN:15-20) ///
	addstat("Mean proportion sold",	`cmean') ///
	addtext(Year FE, YES, Location FE, YES, Other controls, YES) alpha(0.01, 0.05) ///
	symbol(***, **) nodepvar		

********************************************************************************
/*

		(2009, 2011, 2013)
*/

use "$main/TanPanel.dta",clear
keep if SSP
keep if longp==1
keep if !missing(production)
keep if production>0
bysort id (t): drop if _N == 1

foreach i in wagecashsh ofsecashsh nonlcashsh {
	
replace `i' = 0 if `i' ==. & cci!=.

}

gl a 	cherd traderdens insbuydensd farmsize wagecashsh ofsecashsh nonlcashsh ///
		Lnrvharvest litrate hhsize nasset livestock	cereals rootubs grainlg ///
		oilseed frutveg trecrop indcrop roadensity distmarket
		
foreach v in $a {

egen m_`v' = mean(`v'),by(id)

}

*------------------------- EXTENSIVE & INTENSIVE MARGIN	------------------------

gl x 	Lnrvharvest agehead i.female litrate hhsize nasset livestock			///
		i.cereals i.rootubs i.grainlg i.oilseed i.frutveg i.trecrop i.indcrop i.rural i.t 
		
gl w1	c.traderdens##c.traderdens i.insbuydensd farmsize ///
		wagecashsh ofsecashsh nonlcashsh roadensity distmarket i.favzone
		
gl w2	traderdens i.insbuydensd c.farmsize##c.farmsize ///
		wagecashsh ofsecashsh nonlcashsh roadensity distmarket i.favzone

gl m1 	m_cherd c.m_traderdens##c.m_traderdens m_insbuydensd m_farmsize ///
		m_wagecashsh m_ofsecashsh m_nonlcashsh m_Lnrvharvest m_litrate m_hhsize ///
		m_nasset m_livestock m_cereals m_rootubs m_grainlg  ///
		m_oilseed m_frutveg m_trecrop m_indcrop m_roadensity m_distmarket
		
gl m2 	m_cherd m_traderdens m_insbuydensd c.m_farmsize##c.m_farmsize ///
		m_wagecashsh m_ofsecashsh m_nonlcashsh m_Lnrvharvest m_litrate m_hhsize ///
		m_nasset m_livestock m_cereals m_rootubs m_grainlg  ///
		m_oilseed m_frutveg m_trecrop m_indcrop m_roadensity m_distmarket
		

qui svy: churdle exp rvalsalesT cherd $w2 $x $m2, select(cherd $w1 $x $m1) ll(0)
predict y, pr(0,.)
sum y,meanonly
local cmean = r(mean)

lab var cherd "Proportion sold by peers"
qui margins if e(sample), dydx(cherd) predict(pr(0,.)) vce(unconditional) post
nlcom	(cherd:		    _b[cherd]), post
est store tan_mp2

			
outreg2 using "$tables/TableA12a.doc", dec(3) adec(3) label ctitle(TAN:09-13) ///
	addstat("Market participation", 		`cmean') ///
	addtext(Year FE, YES, Location FE, YES, Other controls, YES) alpha(0.01, 0.05) ///
	symbol(***, **) nodepvar	

*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

qui svy: churdle exp rvalsalesT cherd $w2 $x $m2, select(cherd $w1 $x $m1) ll(0)
drop y
predict y
sum y,meanonly
local cmean = r(mean)

lab var cherd "Proportion sold by peers"
qui margins if e(sample), dydx(cherd) vce(unconditional) post
nlcom	(cherd:		    _b[cherd]), post
est store tan_im2
			
outreg2 using "$tables/TableA12b.doc", dec(0) adec(3) label ctitle(TAN:09-13) ///
	addstat("Mean value sold ($)", 		`cmean') ///
	addtext(Year FE, YES, Location FE, YES, Other controls, YES) alpha(0.01, 0.05) ///
	symbol(***, **) nodepvar		

*------------------------------- INTENSITY	------------------------------------

gl x 	Lnrvharvest agehead i.female litrate hhsize nasset livestock			///
		i.cereals i.rootubs i.grainlg i.oilseed i.frutveg i.trecrop i.indcrop i.rural i.t 
		
gl m 	m_cherd c.m_traderdens##c.m_traderdens m_insbuydensd m_farmsize m_wagecashsh m_ofsecashsh m_nonlcashsh ///
		m_Lnrvharvest m_litrate m_hhsize m_nasset m_livestock m_cereals m_rootubs m_grainlg ///
		m_oilseed m_frutveg m_trecrop m_indcrop m_roadensity m_distmarket
		
gl w	c.traderdens##c.traderdens i.insbuydensd farmsize ///
		wagecashsh ofsecashsh nonlcashsh roadensity distmarket i.favzone

qui svy: fracreg probit cci cherd $w $x $m
drop y
predict y
sum y,meanonly
local cmean = r(mean)

lab var cherd "Proportion sold by peers"
qui margins if e(sample), dydx(cherd) vce(unconditional) post
nlcom	(cherd:		    _b[cherd]), post
est store tan_in2
		
outreg2 using "$tables/TableA12c.doc", dec(3) adec(3) label ctitle(TAN:09-13) ///
	addstat("Mean proportion sold",	`cmean') ///
	addtext(Year FE, YES, Location FE, YES, Other controls, YES) alpha(0.01, 0.05) ///
	symbol(***, **) nodepvar

*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

/*

			UGANDA

		  (2016 & 2020)
*/

use "$main/UgaPanel.dta",clear
keep if SSP
keep if short==1
keep if !missing(production)
keep if production>0
bysort id (t): drop if _N == 1

foreach i in wagecashsh ofsecashsh nonlcashsh {
	
replace `i' = 0 if `i' ==. & cci!=.

}

gl a 	cherd traderdens insbuydensd farmsize wagecashsh ofsecashsh nonlcashsh ///
		Lnrvharvest litrate hhsize nasset livestock	cereals rootubs grainlg ///
		oilseed frutveg trecrop indcrop roadensity distmarket
		
foreach v in $a {

egen m_`v' = mean(`v'),by(id)

}

*------------------------- EXTENSIVE & INTENSIVE MARGIN	------------------------

gl x 	Lnrvharvest agehead i.female litrate hhsize nasset livestock			///
		i.cereals i.rootubs i.grainlg i.oilseed i.frutveg i.trecrop i.indcrop i.rural i.t 
		
gl m1 	c.m_cherd##c.m_cherd m_traderdens m_insbuydensd c.m_farmsize##c.m_farmsize ///
		m_wagecashsh m_ofsecashsh m_nonlcashsh m_Lnrvharvest m_litrate m_hhsize ///
		m_nasset m_livestock m_cereals m_rootubs m_grainlg  ///
		m_oilseed m_frutveg m_trecrop m_indcrop c.m_roadensity##c.m_roadensity m_distmarket
		
gl m2 	m_cherd m_traderdens m_insbuydensd m_farmsize ///
		m_wagecashsh m_ofsecashsh m_nonlcashsh m_Lnrvharvest m_litrate m_hhsize ///
		m_nasset m_livestock m_cereals m_rootubs m_grainlg  ///
		m_oilseed m_frutveg m_trecrop m_indcrop m_roadensity m_distmarket

gl w1	traderdens i.insbuydensd c.farmsize##c.farmsize ///
		wagecashsh ofsecashsh nonlcashsh c.roadensity##c.roadensity distmarket i.favzone

gl w2	traderdens i.insbuydensd farmsize ///
		wagecashsh ofsecashsh nonlcashsh roadensity distmarket i.favzone

qui svy: churdle exp rvalsalesT cherd $w2 $x $m2, select(c.cherd##c.cherd $w1 $x $m1) ll(0)
predict y, pr(0,.)
sum y,meanonly
local cmean = r(mean)

lab var cherd "Proportion sold by peers"
qui margins if e(sample), dydx(cherd) predict(pr(0,.)) vce(unconditional) post
nlcom	(cherd:		    _b[cherd]), post
est store uga_mp1
			
outreg2 using "$tables/Table12a.doc", dec(3) adec(3) label ctitle(UGA:16-20) ///
	addstat("Market participation", 		`cmean') ///
	addtext(Year FE, YES, Location FE, YES, Other controls, YES) alpha(0.01, 0.05) ///
	symbol(***, **) nodepvar	

*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

qui svy: churdle exp rvalsalesT cherd $w2 $x $m2, select(c.cherd##c.cherd $w1 $x $m1) ll(0)
drop y
predict y
sum y,meanonly
local cmean = r(mean)

lab var cherd "Proportion sold by peers"
qui margins if e(sample), dydx(cherd) vce(unconditional) post
nlcom	(cherd:		    _b[cherd]), post
est store uga_im1
			
outreg2 using "$tables/Table12b.doc", dec(0) adec(3) label ctitle(UGA:16-20) ///
	addstat("Mean value sold ($)", 		`cmean') ///
	addtext(Year FE, YES, Location FE, YES, Other controls, YES) alpha(0.01, 0.05) ///
	symbol(***, **) nodepvar		

*------------------------------- INTENSITY	------------------------------------

gl x 	Lnrvharvest agehead i.female litrate hhsize nasset livestock			///
		i.cereals i.rootubs i.grainlg i.oilseed i.frutveg i.trecrop i.indcrop i.rural i.t 
		
gl m 	m_cherd m_traderdens m_insbuydensd c.m_farmsize##c.m_farmsize ///
		m_wagecashsh m_ofsecashsh m_nonlcashsh m_Lnrvharvest m_litrate m_hhsize ///
		m_nasset m_livestock m_cereals m_rootubs m_grainlg ///
		m_oilseed m_frutveg m_trecrop m_indcrop m_roadensity m_distmarket

gl w	traderdens i.insbuydensd c.farmsize##c.farmsize ///
		wagecashsh ofsecashsh nonlcashsh roadensity distmarket i.favzone

qui svy: fracreg probit cci cherd $w $x $m
drop y
predict y
sum y,meanonly
local cmean = r(mean)

lab var cherd "Proportion sold by peers"
qui margins if e(sample), dydx(cherd) vce(unconditional) post
nlcom	(cherd:		    _b[cherd]), post
est store uga_in1
		
outreg2 using "$tables/Table12c.doc", dec(3) adec(3) label ctitle(UGA:16-20) ///
	addstat("Mean proportion sold",	`cmean') ///
	addtext(Year FE, YES, Location FE, YES, Other controls, YES) alpha(0.01, 0.05) ///
	symbol(***, **) nodepvar		


********************************************************************************

/*

	  (2010, 2012, 2014)
*/

use "$main/UgaPanel.dta",clear
keep if SSP
keep if medip==1
keep if !missing(production)
keep if production>0
bysort id (t): drop if _N == 1

foreach i in wagecashsh ofsecashsh nonlcashsh {
	
replace `i' = 0 if `i' ==. & cci!=.

}

gl a 	cherd traderdens insbuydensd farmsize wagecashsh ofsecashsh nonlcashsh ///
		Lnrvharvest litrate hhsize nasset livestock	cereals rootubs grainlg ///
		oilseed frutveg trecrop indcrop roadensity distmarket
		
foreach v in $a {

egen m_`v' = mean(`v'),by(id)

}

*------------------------- EXTENSIVE & INTENSIVE MARGIN	------------------------

gl x 	Lnrvharvest agehead i.female litrate hhsize nasset livestock			///
		i.cereals i.rootubs i.grainlg i.oilseed i.frutveg i.trecrop i.indcrop i.rural i.t 
		
gl w1	traderdens i.insbuydensd farmsize ///
		wagecashsh ofsecashsh nonlcashsh roadensity distmarket i.favzone
		
gl w2	traderdens i.insbuydensd farmsize ///
		wagecashsh ofsecashsh nonlcashsh roadensity distmarket i.favzone

gl m1 	m_cherd m_traderdens m_insbuydensd m_farmsize ///
		m_wagecashsh m_ofsecashsh m_nonlcashsh m_Lnrvharvest m_litrate m_hhsize ///
		m_nasset m_livestock m_cereals m_rootubs m_grainlg  ///
		m_oilseed m_frutveg m_trecrop m_indcrop m_roadensity m_distmarket
		
gl m2 	m_cherd m_traderdens m_insbuydensd m_farmsize ///
		m_wagecashsh m_ofsecashsh m_nonlcashsh m_Lnrvharvest m_litrate m_hhsize ///
		m_nasset m_livestock m_cereals m_rootubs m_grainlg  ///
		m_oilseed m_frutveg m_trecrop m_indcrop m_roadensity m_distmarket

qui svy: churdle exp rvalsalesT cherd $w2 $x $m2, select(cherd $w1 $x $m1) ll(0)
predict y, pr(0,.)
sum y,meanonly
local cmean = r(mean)

lab var cherd "Proportion sold by peers"
qui margins if e(sample), dydx(cherd) predict(pr(0,.)) vce(unconditional) post
nlcom	(cherd:		    _b[cherd]), post
est store uga_mp2
			
outreg2 using "$tables/TableA12a.doc", dec(3) adec(3) label ctitle(UGA:10-14) ///
	addstat("Market participation", 		`cmean') ///
	addtext(Year FE, YES, Location FE, YES, Other controls, YES) alpha(0.01, 0.05) ///
	symbol(***, **) nodepvar	

*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

qui svy: churdle exp rvalsalesT cherd $w2 $x $m2, select(cherd $w1 $x $m1) ll(0)
drop y
predict y
sum y,meanonly
local cmean = r(mean)

lab var cherd "Proportion sold by peers"
qui margins if e(sample), dydx(cherd) vce(unconditional) post
nlcom	(cherd:		    _b[cherd]), post
est store uga_im2
			
outreg2 using "$tables/TableA12b.doc", dec(0) adec(3) label ctitle(UGA:10-14) ///
	addstat("Mean value sold ($)", 		`cmean') ///
	addtext(Year FE, YES, Location FE, YES, Other controls, YES) alpha(0.01, 0.05) ///
	symbol(***, **) nodepvar		

*------------------------------- INTENSITY	------------------------------------

gl x 	Lnrvharvest agehead i.female litrate hhsize nasset livestock			///
		i.cereals i.rootubs i.grainlg i.oilseed i.frutveg i.trecrop i.indcrop i.rural i.t 
		
gl m 	m_cherd m_traderdens m_insbuydensd m_farmsize ///
		m_wagecashsh m_ofsecashsh m_nonlcashsh m_Lnrvharvest m_litrate m_hhsize ///
		m_nasset m_livestock m_cereals m_rootubs m_grainlg ///
		m_oilseed m_frutveg m_trecrop m_indcrop m_roadensity m_distmarket

gl w 	traderdens i.insbuydensd farmsize ///
		wagecashsh ofsecashsh nonlcashsh roadensity distmarket i.favzone

qui svy: fracreg probit cci cherd $w $x $m
drop y
predict y
sum y,meanonly
local cmean = r(mean)

lab var cherd "Proportion sold by peers"
qui margins if e(sample), dydx(cherd) vce(unconditional) post
nlcom	(cherd:		    _b[cherd]), post
est store uga_in2
		
outreg2 using "$tables/TableA12c.doc", dec(3) adec(3) label ctitle(UGA:10-14) ///
	addstat("Mean proportion sold",	`cmean') ///
	addtext(Year FE, YES, Location FE, YES, Other controls, YES) alpha(0.01, 0.05) ///
	symbol(***, **) nodepvar		

*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

/*

			ETHIOPIA

		(2012, 2014 & 2016)
*/

use "$main/EthPanel.dta",clear
keep if SSP
keep if longp==1
keep if !missing(production)
keep if production>0
bysort id (t): drop if _N == 1

foreach i in wagecashsh ofsecashsh nonlcashsh {
	
replace `i' = 0 if `i' ==. & cci!=.

}

gl a 	cherd traderdens insbuydensd farmsize wagecashsh ofsecashsh nonlcashsh ///
		Lnrvharvest litrate hhsize nasset livestock	cereals rootubs grainlg ///
		oilseed frutveg trecrop indcrop roadensity distmarket
		
foreach v in $a {

egen m_`v' = mean(`v'),by(id)

}

*------------------------- EXTENSIVE & INTENSIVE MARGIN	------------------------

gl x 	Lnrvharvest agehead i.female litrate hhsize nasset livestock			///
		i.cereals i.rootubs i.grainlg i.oilseed i.frutveg i.trecrop i.indcrop i.rural i.t 
				
gl m1 	m_cherd c.m_traderdens##c.m_traderdens m_insbuydensd m_farmsize ///
		m_wagecashsh m_ofsecashsh m_nonlcashsh m_Lnrvharvest m_litrate m_hhsize ///
		m_nasset m_livestock m_cereals m_rootubs m_grainlg  ///
		m_oilseed m_frutveg m_trecrop m_indcrop m_roadensity m_distmarket

gl m2 	c.m_cherd##c.m_cherd c.m_traderdens##c.m_traderdens m_insbuydensd m_farmsize ///
		m_wagecashsh m_ofsecashsh m_nonlcashsh m_Lnrvharvest m_litrate m_hhsize ///
		m_nasset m_livestock m_cereals m_rootubs m_grainlg  ///
		m_oilseed m_frutveg m_trecrop m_indcrop m_roadensity c.m_distmarket##c.m_distmarket

gl w1	c.traderdens##c.traderdens i.insbuydensd farmsize ///
		wagecashsh ofsecashsh nonlcashsh roadensity distmarket i.favzone

gl w2	c.traderdens##c.traderdens i.insbuydensd farmsize ///
		wagecashsh ofsecashsh nonlcashsh roadensity c.distmarket##c.distmarket i.favzone

qui svy: churdle exp rvalsalesT c.cherd##c.cherd $w2 $x $m2, select(cherd $w1 $x $m1) ll(0)
predict y, pr(0,.)
sum y,meanonly
local cmean = r(mean)

lab var cherd "Proportion sold by peers"
qui margins if e(sample), dydx(cherd) predict(pr(0,.)) vce(unconditional) post
nlcom	(cherd:		    _b[cherd]), post
est store eth_mp1
			
outreg2 using "$tables/Table12a.doc", dec(3) adec(3) label ctitle(ETH:12-16) ///
	addstat("Market participation", 		`cmean') ///
	addtext(Year FE, YES, Location FE, YES, Other controls, YES) alpha(0.01, 0.05) ///
	symbol(***, **) nodepvar	

*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

qui svy: churdle exp rvalsalesT c.cherd##c.cherd $w2 $x $m2, select(cherd $w1 $x $m1) ll(0)
drop y
predict y
sum y,meanonly
local cmean = r(mean)

lab var cherd "Proportion sold by peers"
qui margins if e(sample), dydx(cherd) vce(unconditional) post
nlcom	(cherd:		    _b[cherd]), post
est store eth_im1
			
outreg2 using "$tables/Table12b.doc", dec(0) adec(3) label ctitle(ETH:12-16) ///
	addstat("Mean value sold ($)", 		`cmean') ///
	addtext(Year FE, YES, Location FE, YES, Other controls, YES) alpha(0.01, 0.05) ///
	symbol(***, **) nodepvar		

*------------------------------- INTENSITY	------------------------------------

gl x 	Lnrvharvest agehead i.female litrate hhsize nasset livestock			///
		i.cereals i.rootubs i.grainlg i.oilseed i.frutveg i.trecrop i.indcrop i.rural i.t 
		
gl m 	c.m_cherd##c.m_cherd m_traderdens m_insbuydensd m_farmsize m_wagecashsh m_ofsecashsh m_nonlcashsh ///
		m_Lnrvharvest m_litrate m_hhsize m_nasset m_livestock m_cereals m_rootubs m_grainlg ///
		m_oilseed m_frutveg m_trecrop m_indcrop m_roadensity m_distmarket
		
gl w 	traderdens i.insbuydensd farmsize ///
		wagecashsh ofsecashsh nonlcashsh roadensity distmarket i.favzone

qui svy: fracreg probit cci c.cherd##c.cherd $w $x $m
drop y
predict y
sum y,meanonly
local cmean = r(mean)

lab var cherd "Proportion sold by peers"
qui margins if e(sample), dydx(cherd) vce(unconditional) post
nlcom	(cherd:		    _b[cherd]), post
est store eth_in1
		
outreg2 using "$tables/Table12c.doc", dec(3) adec(3) label ctitle(ETH:12-16) ///
	addstat("Mean proportion sold",	`cmean') ///
	addtext(Year FE, YES, Location FE, YES, Other controls, YES) alpha(0.01, 0.05) ///
	symbol(***, **) nodepvar		


********************************************************************************

/*

			  2019
*/

use "$main/EthPanel.dta",clear
keep if t==4
keep if SSP
keep if !missing(production)
keep if production>0

foreach i in wagecashsh ofsecashsh nonlcashsh {
	
replace `i' = 0 if `i' ==. & cci!=.

}

*------------------------- EXTENSIVE & INTENSIVE MARGIN	------------------------

gl x 	Lnrvharvest agehead i.female litrate hhsize nasset livestock			///
		i.cereals i.rootubs i.grainlg i.oilseed i.frutveg i.trecrop i.indcrop  
				
gl w1	c.traderdens##c.traderdens i.insbuydensd farmsize ///
		wagecashsh ofsecashsh nonlcashsh c.roadensity##c.roadensity distmarket i.favzone

gl w2	traderdens i.insbuydensd farmsize ///
		wagecashsh ofsecashsh nonlcashsh roadensity distmarket i.favzone

qui svy: churdle exp rvalsalesT c.cherd##c.cherd $w2 $x, select(cherd $w1 $x) ll(0)
predict y, pr(0,.)
sum y,meanonly
local cmean = r(mean)

lab var cherd "Proportion sold by peers"
qui margins if e(sample), dydx(cherd) predict(pr(0,.)) vce(unconditional) post
nlcom	(cherd:		    _b[cherd]), post
est store eth_mp2
			
outreg2 using "$tables/TableA12a.doc", dec(3) adec(3) label ctitle(ETH:2019) ///
	addstat("Market participation", 		`cmean') ///
	addtext(Year FE, NO, Location FE, YES, Other controls, YES) alpha(0.01, 0.05) ///
	symbol(***, **) nodepvar	

*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

qui svy: churdle exp rvalsalesT c.cherd##c.cherd $w2 $x, select(cherd $w1 $x) ll(0)
drop y
predict y
sum y,meanonly
local cmean = r(mean)

lab var cherd "Proportion sold by peers"
qui margins if e(sample), dydx(cherd) vce(unconditional) post
nlcom	(cherd:		    _b[cherd]), post
est store eth_im2
			
outreg2 using "$tables/TableA12b.doc", dec(0) adec(3) label ctitle(ETH:2019) ///
	addstat("Mean value sold ($)", 		`cmean') ///
	addtext(Year FE, NO, Location FE, YES, Other controls, YES) alpha(0.01, 0.05) ///
	symbol(***, **) nodepvar		

*------------------------------- INTENSITY	------------------------------------

gl x 	Lnrvharvest agehead i.female litrate hhsize nasset livestock			///
		i.cereals i.rootubs i.grainlg i.oilseed i.frutveg i.trecrop i.indcrop 
				
gl w 	traderdens i.insbuydensd farmsize ///
		wagecashsh ofsecashsh nonlcashsh roadensity distmarket i.favzone

qui svy: fracreg probit cci c.cherd##c.cherd $w $x
drop y
predict y
sum y,meanonly
local cmean = r(mean)

lab var cherd "Proportion sold by peers"
qui margins if e(sample), dydx(cherd) vce(unconditional) post
nlcom	(cherd:		    _b[cherd]), post
est store eth_in2
		
outreg2 using "$tables/TableA12c.doc", dec(3) adec(3) label ctitle(ETH:2019) ///
	addstat("Mean proportion sold",	`cmean') ///
	addtext(Year FE, NO, Location FE, YES, Other controls, YES) alpha(0.01, 0.05) ///
	symbol(***, **) nodepvar		

*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

/*

			MALAWI

	(2011, 2013, 2016 & 2019)
*/

use "$main/MalPanel.dta",clear
keep if SSP
keep if !missing(production)
keep if production>0
bysort id (t): drop if _N == 1

foreach i in wagecashsh ofsecashsh nonlcashsh {
	
replace `i' = 0 if `i' ==. & cci!=.

}

gl a 	cherd traderdens insbuydensd farmsize wagecashsh ofsecashsh nonlcashsh ///
		Lnrvharvest litrate hhsize nasset livestock	cereals rootubs grainlg ///
		oilseed frutveg trecrop indcrop roadensity distmarket
		
foreach v in $a {

egen m_`v' = mean(`v'),by(id)

}

*------------------------- EXTENSIVE & INTENSIVE MARGIN	------------------------

gl x 	Lnrvharvest agehead i.female litrate hhsize nasset livestock			///
		i.cereals i.rootubs i.grainlg i.oilseed i.frutveg i.trecrop i.indcrop i.rural i.t 
				
gl m1 	m_cherd m_traderdens m_insbuydensd m_farmsize ///
		m_wagecashsh m_ofsecashsh m_nonlcashsh m_Lnrvharvest m_litrate m_hhsize ///
		m_nasset m_livestock m_cereals m_rootubs m_grainlg  ///
		m_oilseed m_frutveg m_trecrop m_indcrop m_roadensity c.m_distmarket##c.m_distmarket

gl m2 	m_cherd m_traderdens m_insbuydensd c.m_farmsize##c.m_farmsize ///
		m_wagecashsh m_ofsecashsh m_nonlcashsh m_Lnrvharvest m_litrate m_hhsize ///
		m_nasset m_livestock m_cereals m_rootubs m_grainlg  ///
		m_oilseed m_frutveg m_trecrop m_indcrop m_roadensity m_distmarket
		
gl w1	traderdens i.insbuydensd farmsize ///
		wagecashsh ofsecashsh nonlcashsh roadensity c.distmarket##c.distmarket i.favzone
		
gl w2	traderdens i.insbuydensd c.farmsize##c.farmsize ///
		wagecashsh ofsecashsh nonlcashsh roadensity distmarket i.favzone

qui svy: churdle exp rvalsalesT cherd $w2 $x $m2, select(cherd $w1 $x $m1) ll(0)
predict y, pr(0,.)
sum y,meanonly
local cmean = r(mean)

lab var cherd "Proportion sold by peers"
qui margins if e(sample), dydx(cherd) predict(pr(0,.)) vce(unconditional) post
nlcom	(cherd:		    _b[cherd]), post
est store mal_mp1
			
outreg2 using "$tables/Table12a.doc", dec(3) adec(3) label ctitle(MAL:11-19) ///
	addstat("Market participation", 		`cmean') ///
	addtext(Year FE, YES, Location FE, YES, Other controls, YES) alpha(0.01, 0.05) ///
	symbol(***, **) nodepvar	

*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

qui svy: churdle exp rvalsalesT cherd $w2 $x $m2, select(cherd $w1 $x $m1) ll(0)
drop y
predict y
sum y,meanonly
local cmean = r(mean)

lab var cherd "Proportion sold by peers"
qui margins if e(sample), dydx(cherd) vce(unconditional) post
nlcom	(cherd:		    _b[cherd]), post
est store mal_im1
			
outreg2 using "$tables/Table12b.doc", dec(0) adec(3) label ctitle(MAL:11-19) ///
	addstat("Mean value sold ($)", 		`cmean') ///
	addtext(Year FE, YES, Location FE, YES, Other controls, YES) alpha(0.01, 0.05) ///
	symbol(***, **) nodepvar		

*------------------------------- INTENSITY	------------------------------------

gl x 	Lnrvharvest agehead i.female litrate hhsize nasset livestock			///
		i.cereals i.rootubs i.grainlg i.oilseed i.frutveg i.trecrop i.indcrop i.rural i.t 
		
gl m 	c.m_cherd##c.m_cherd m_traderdens m_insbuydensd m_farmsize m_wagecashsh m_ofsecashsh m_nonlcashsh ///
		m_Lnrvharvest m_litrate m_hhsize m_nasset m_livestock m_cereals m_rootubs m_grainlg ///
		m_oilseed m_frutveg m_trecrop m_indcrop m_roadensity m_distmarket
		
gl w	traderdens i.insbuydensd farmsize ///
		wagecashsh ofsecashsh nonlcashsh roadensity distmarket i.favzone

qui svy: fracreg probit cci c.cherd##c.cherd $w $x $m
drop y
predict y
sum y,meanonly
local cmean = r(mean)

lab var cherd "Proportion sold by peers"
qui margins if e(sample), dydx(cherd) vce(unconditional) post
nlcom	(cherd:		    _b[cherd]), post
est store mal_in1
		
outreg2 using "$tables/Table12c.doc", dec(3) adec(3) label ctitle(MAL:11-19) ///
	addstat("Mean proportion sold",	`cmean') ///
	addtext(Year FE, YES, Location FE, YES, Other controls, YES) alpha(0.01, 0.05) ///
	symbol(***, **) nodepvar		

********************************************************************************

/*

			MALAWI

		  2016 & 2019
*/

use "$main/MalPanel.dta",clear
keep if SSP
keep if short==1
keep if !missing(production)
keep if production>0
bysort id (t): drop if _N == 1

foreach i in wagecashsh ofsecashsh nonlcashsh {
	
replace `i' = 0 if `i' ==. & cci!=.

}

gl a 	cherd traderdens insbuydensd farmsize wagecashsh ofsecashsh nonlcashsh ///
		Lnrvharvest litrate hhsize nasset livestock	cereals rootubs grainlg ///
		oilseed frutveg trecrop indcrop roadensity distmarket
		
foreach v in $a {

egen m_`v' = mean(`v'),by(id)

}

*------------------------- EXTENSIVE & INTENSIVE MARGIN	------------------------

gl x 	Lnrvharvest agehead i.female litrate hhsize nasset livestock			///
		i.cereals i.rootubs i.grainlg i.oilseed i.frutveg i.trecrop i.indcrop i.rural i.t 
				
gl m1 	m_cherd m_traderdens m_insbuydensd m_farmsize ///
		m_wagecashsh m_ofsecashsh m_nonlcashsh m_Lnrvharvest m_litrate m_hhsize ///
		m_nasset m_livestock m_cereals m_rootubs m_grainlg  ///
		m_oilseed m_frutveg m_trecrop m_indcrop m_roadensity m_distmarket
		
gl m2 	m_cherd m_traderdens m_insbuydensd m_farmsize ///
		m_wagecashsh m_ofsecashsh m_nonlcashsh m_Lnrvharvest m_litrate m_hhsize ///
		m_nasset m_livestock m_cereals m_rootubs m_grainlg  ///
		m_oilseed m_frutveg m_trecrop m_indcrop m_roadensity m_distmarket
		
gl w1	traderdens i.insbuydensd farmsize ///
		wagecashsh ofsecashsh nonlcashsh roadensity distmarket i.favzone

gl w2	traderdens i.insbuydensd farmsize ///
		wagecashsh ofsecashsh nonlcashsh roadensity distmarket i.favzone
		
qui svy: churdle exp rvalsalesT cherd $w2 $x $m2, select(cherd $w1 $x $m1) ll(0)
predict y, pr(0,.)
sum y,meanonly
local cmean = r(mean)

lab var cherd "Proportion sold by peers"
qui margins if e(sample), dydx(cherd) predict(pr(0,.)) vce(unconditional) post
nlcom	(cherd:		    _b[cherd]), post
est store mal_mp2
			
outreg2 using "$tables/TableA12a.doc", dec(3) adec(3) label ctitle(MAL:16-19) ///
	addstat("Market participation", 		`cmean') ///
	addtext(Year FE, YES, Location FE, YES, Other controls, YES) alpha(0.01, 0.05) ///
	symbol(***, **) nodepvar	

*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

qui svy: churdle exp rvalsalesT cherd $w2 $x $m2, select(cherd $w1 $x $m1) ll(0)
drop y
predict y
sum y,meanonly
local cmean = r(mean)

lab var cherd "Proportion sold by peers"
qui margins if e(sample), dydx(cherd) vce(unconditional) post
nlcom	(cherd:		    _b[cherd]), post
est store mal_im2
			
outreg2 using "$tables/TableA12b.doc", dec(0) adec(3) label ctitle(MAL:16-19) ///
	addstat("Mean value sold ($)", 		`cmean') ///
	addtext(Year FE, YES, Location FE, YES, Other controls, YES) alpha(0.01, 0.05) ///
	symbol(***, **) nodepvar		

*------------------------------- INTENSITY	------------------------------------

gl x 	Lnrvharvest agehead i.female litrate hhsize nasset livestock			///
		i.cereals i.rootubs i.grainlg i.oilseed i.frutveg i.trecrop i.indcrop i.rural i.t 
		
gl m 	m_cherd m_traderdens m_insbuydensd m_farmsize m_wagecashsh m_ofsecashsh m_nonlcashsh ///
		m_Lnrvharvest m_litrate m_hhsize m_nasset m_livestock m_cereals m_rootubs m_grainlg ///
		m_oilseed m_frutveg m_trecrop m_indcrop m_roadensity m_distmarket
		
gl w	traderdens i.insbuydensd farmsize ///
		wagecashsh ofsecashsh nonlcashsh roadensity distmarket i.favzone

qui svy: fracreg probit cci cherd $w $x $m
drop y
predict y
sum y,meanonly
local cmean = r(mean)

lab var cherd "Proportion sold by peers"
qui margins if e(sample), dydx(cherd) vce(unconditional) post
nlcom	(cherd:		    _b[cherd]), post
est store mal_in2
		
outreg2 using "$tables/TableA12c.doc", dec(3) adec(3) label ctitle(MAL:16-19) ///
	addstat("Mean proportion sold",	`cmean') ///
	addtext(Year FE, YES, Location FE, YES, Other controls, YES) alpha(0.01, 0.05) ///
	symbol(***, **) nodepvar		


************************************ COEFPLOTS	********************************

********************************************************************************

coefplot(gha_mp1,		ms(D)  mc(black) ciopts(recast(rcap) lc(black) lp(longdash)))	///
		(nig_mp1,		ms(D)  mc(black) ciopts(recast(rcap) lc(black) lp(longdash)))	///
		(tan_mp1,		ms(D)  mc(black) ciopts(recast(rcap) lc(black) lp(longdash)))	///
		(uga_mp1,		ms(D)  mc(black) ciopts(recast(rcap) lc(black) lp(longdash)))	///
		(eth_mp1,		ms(D)  mc(black) ciopts(recast(rcap) lc(black) lp(longdash)))	///
		(mal_mp1,		ms(D)  mc(black) ciopts(recast(rcap) lc(black) lp(longdash))),	///
		asequation swapnames xline(0, lp(solid) lc(red)) levels(95) legend(off) 	///
     eqren(gha_mp1 = "GHA (06-17)" 		///
           nig_mp1 = "NIG (11-16)"		///
		   tan_mp1 = "TAN (15-20)" 		///
           uga_mp1 = "UGA (16-20)"		///
           eth_mp1 = "ETH (12-16)"		///
           mal_mp1 = "MAL (11-19)")		///
   		   ylab(, nogrid) xlab(, nogrid) ///
		mlabel format(%9.2f) mlabpos(12) mlabcol(black) mlabgap(*2) grid(none)		///
		legend(off) xtitle("Marginal effect") xlab(-1(.5)1, nogrid format(%9.1f)) ///
		title("{bf: (A)}" "{bf:Main regressions with most}" "{bf: recent panels/repeated cross-section}", size(medsmall)) name(graph1, replace) 
	
*-------------------------------------------------------------------------------

coefplot(gha_mp2,		ms(D)  mc(black) ciopts(recast(rcap) lc(black) lp(longdash)))	///
		(nig_mp2,		ms(D)  mc(black) ciopts(recast(rcap) lc(black) lp(longdash)))	///
		(tan_mp2,		ms(D)  mc(black) ciopts(recast(rcap) lc(black) lp(longdash)))	///
		(uga_mp2,		ms(D)  mc(black) ciopts(recast(rcap) lc(black) lp(longdash)))	///
		(eth_mp2,		ms(D)  mc(black) ciopts(recast(rcap) lc(black) lp(longdash)))	///
		(mal_mp2,		ms(D)  mc(black) ciopts(recast(rcap) lc(black) lp(longdash))),	///
		asequation swapnames xline(0, lp(solid) lc(red)) levels(95) legend(off) 	///
     eqren(gha_mp2 = "GHA (2017)" 		///
           nig_mp2 = "NIG (2019)"			///
		   tan_mp2 = "TAN (09-13)" 		///
           uga_mp2 = "UGA (10-14)"		///
           eth_mp2 = "ETH (2019)"			///
           mal_mp2 = "MAL (16-19)")		///
   		   ylab(, nogrid) xlab(, nogrid) ///
		mlabel format(%9.2f) mlabpos(12) mlabcol(black) mlabgap(*2) grid(none)		///
		legend(off) xtitle("Marginal effect") xlab(-1(.5)1, nogrid format(%9.1f)) /// 
		title("{bf: (B)}" "{bf:Supplementary regressions with}" "{bf: other panels/recent cross-sections}", size(medsmall)) name(graph2, replace) 

*graph combine graph1 graph2, imargin(tiny) col(2) iscale(1) 

graph combine graph1 graph2, col(2) ///
    imargin(0 10 0 10) ///
    xsize(10) ysize(6) ///
    graphregion(margin(zero))

graph export "$figures/Herd_Mpat.tif", as(tif) name("Graph") replace

*===============================================================================

coefplot(gha_im1,		ms(D)  mc(black) ciopts(recast(rcap) lc(black) lp(longdash)))	///
		(nig_im1,		ms(D)  mc(black) ciopts(recast(rcap) lc(black) lp(longdash)))	///
		(tan_im1,		ms(D)  mc(black) ciopts(recast(rcap) lc(black) lp(longdash)))	///
		(uga_im1,		ms(D)  mc(black) ciopts(recast(rcap) lc(black) lp(longdash)))	///
		(eth_im1,		ms(D)  mc(black) ciopts(recast(rcap) lc(black) lp(longdash)))	///
		(mal_im1,		ms(D)  mc(black) ciopts(recast(rcap) lc(black) lp(longdash))),	///
		asequation swapnames xline(0, lp(solid) lc(red)) levels(95) legend(off) 	///
     eqren(gha_im1 = "GHA (06-17)" 		///
           nig_im1 = "NIG (11-16)"		///
		   tan_im1 = "TAN (15-20)" 		///
           uga_im1 = "UGA (16-20)"		///
           eth_im1 = "ETH (12-16)"		///
           mal_im1 = "MAL (11-19)")		///
   		   ylab(, nogrid) xlab(, nogrid) ///
		mlabel format(%9.0f) mlabpos(12) mlabcol(black) mlabgap(*2) grid(none)		///
		legend(off) xtitle("Marginal effect (PPP$)") xlab(-500(500)1500, nogrid format(%9.0f))  ///
		title("{bf: (A)}" "{bf:Main regressions with most}" "{bf: recent panels/repeated cross-section}", size(medsmall)) name(graph1, replace) 
	
*-------------------------------------------------------------------------------

coefplot(gha_im2,		ms(D)  mc(black) ciopts(recast(rcap) lc(black) lp(longdash)))	///
		(nig_im2,		ms(D)  mc(black) ciopts(recast(rcap) lc(black) lp(longdash)))	///
		(tan_im2,		ms(D)  mc(black) ciopts(recast(rcap) lc(black) lp(longdash)))	///
		(uga_im2,		ms(D)  mc(black) ciopts(recast(rcap) lc(black) lp(longdash)))	///
		(eth_im2,		ms(D)  mc(black) ciopts(recast(rcap) lc(black) lp(longdash)))	///
		(mal_im2,		ms(D)  mc(black) ciopts(recast(rcap) lc(black) lp(longdash))),	///
		asequation swapnames xline(0, lp(solid) lc(red)) levels(95) legend(off) 	///
     eqren(gha_im2 = "GHA (2017)" 		///
           nig_im2 = "NIG (2019)"			///
		   tan_im2 = "TAN (09-13)" 		///
           uga_im2 = "UGA (10-14)"		///
           eth_im2 = "ETH (2019)"			///
           mal_im2 = "MAL (16-19)")		///
   		   ylab(, nogrid) xlab(, nogrid) ///
		mlabel format(%9.0f) mlabpos(12) mlabcol(black) mlabgap(*2) grid(none)		///
		legend(off) xtitle("Marginal effect (PPP$)") xlab(-500(500)1500, nogrid format(%9.0f))  ///
		title("{bf: (B)}" "{bf:Supplementary regressions with}" "{bf: other panels/recent cross-sections}", size(medsmall)) name(graph2, replace) 

*graph combine graph1 graph2, imargin(tiny) col(2) iscale(1) 

graph combine graph1 graph2, col(2) ///
    imargin(0 10 0 10) ///
    xsize(10) ysize(6) ///
    graphregion(margin(zero))

graph export "$figures/Herd_Sales.tif", as(tif) name("Graph") replace

*===============================================================================

coefplot(gha_in1,		ms(D)  mc(black) ciopts(recast(rcap) lc(black) lp(longdash)))	///
		(nig_in1,		ms(D)  mc(black) ciopts(recast(rcap) lc(black) lp(longdash)))	///
		(tan_in1,		ms(D)  mc(black) ciopts(recast(rcap) lc(black) lp(longdash)))	///
		(uga_in1,		ms(D)  mc(black) ciopts(recast(rcap) lc(black) lp(longdash)))	///
		(eth_in1,		ms(D)  mc(black) ciopts(recast(rcap) lc(black) lp(longdash)))	///
		(mal_in1,		ms(D)  mc(black) ciopts(recast(rcap) lc(black) lp(longdash))),	///
		asequation swapnames xline(0, lp(solid) lc(red)) levels(95) legend(off) 	///
     eqren(gha_in1 = "GHA (06-17)" 		///
           nig_in1 = "NIG (11-16)"		///
		   tan_in1 = "TAN (15-20)" 		///
           uga_in1 = "UGA (16-20)"		///
           eth_in1 = "ETH (12-16)"		///
           mal_in1 = "MAL (11-19)")		///
   		   ylab(, nogrid) xlab(, nogrid) ///
		mlabel format(%9.2f) mlabpos(12) mlabcol(black) mlabgap(*2) grid(none)		///
		legend(off) xtitle("Marginal effect")  ///
		title("{bf: (A)}" "{bf:Main regressions with most}" "{bf: recent panels/repeated cross-section}", size(medsmall)) name(graph1, replace) 
	
*-------------------------------------------------------------------------------

coefplot(gha_in2,		ms(D)  mc(black) ciopts(recast(rcap) lc(black) lp(longdash)))	///
		(nig_in2,		ms(D)  mc(black) ciopts(recast(rcap) lc(black) lp(longdash)))	///
		(tan_in2,		ms(D)  mc(black) ciopts(recast(rcap) lc(black) lp(longdash)))	///
		(uga_in2,		ms(D)  mc(black) ciopts(recast(rcap) lc(black) lp(longdash)))	///
		(eth_in2,		ms(D)  mc(black) ciopts(recast(rcap) lc(black) lp(longdash)))	///
		(mal_in2,		ms(D)  mc(black) ciopts(recast(rcap) lc(black) lp(longdash))),	///
		asequation swapnames xline(0, lp(solid) lc(red)) levels(95) legend(off) 	///
     eqren(gha_in2 = "GHA (2017)" 		///
           nig_in2 = "NIG (2019)"			///
		   tan_in2 = "TAN (09-13)" 		///
           uga_in2 = "UGA (10-14)"		///
           eth_in2 = "ETH (2019)"			///
           mal_in2 = "MAL (16-19)")		///
   		   ylab(, nogrid) xlab(, nogrid) ///
		mlabel format(%9.2f) mlabpos(12) mlabcol(black) mlabgap(*2) grid(none)		///
		legend(off) xtitle("Marginal effect")  ///xlab(-.1(.1).4, nogrid format(%9.1f))
		title("{bf: (B)}" "{bf:Supplementary regressions with}" "{bf: other panels/recent cross-sections}", size(medsmall)) name(graph2, replace) 

*graph combine graph1 graph2, imargin(tiny) col(2) iscale(1) 
graph combine graph1 graph2, col(2) ///
    imargin(0 10 0 10) ///
    xsize(10) ysize(6) ///
    graphregion(margin(zero))

graph export "$figures/Herd_Share.tif", as(tif) name("Graph") replace